【发布时间】:2020-01-30 14:34:31
【问题描述】:
我正在处理一个涵盖多个国家、变量和年份的数据集。它目前的组织范围很广(实际上是大约 30 年,每个国家/地区有 5 个不同的变量):
country measure yr1995 yr1996 yr1997
USA A 5 4 1
USA B 1 2 1
USA C 0 4 2
UK A 2 4 9
UK B 2 8 4
UK C 2 4 1
我想要的是像这样重新排列数据:
country year A B C
USA 1995 5 1 0
USA 1996 4 2 4
USA 1997 1 1 2
UK 1995 2 2 2
UK 1996 4 8 4
UK 1997 9 4 1
我尝试使用reshape long yr, i(country) j(year),但收到以下错误消息:
variable id does not uniquely identify the observations
Your data are currently wide. You are performing a reshape long. You specified i(country) and j(year). In
the current wide form, variable country should uniquely identify the observations.
我认为这是因为country 不是唯一的长变量? (measure也是?)
除了解决这个问题和安排年长而不是宽,我认为这个命令不会完成将不同变量(A、B、C)移动到宽格式作为列标题的其他任务。
我需要为此使用单独的reshape wide 命令吗?或者有什么方法可以扩展命令以同时执行这两项操作?
【问题讨论】: