全部版块 我的主页
论坛 计量经济学与统计论坛 五区 计量经济学与统计软件 Stata专版
2287 6
2013-08-16
数据结构变化。
数据举例如下:
code    country       jan1996   feb1996  ...........dec2012
1111      US               2344        3435                      5656
1232      UK               34343       9000                     938
1224       US               498           4595                   9485
.........无数多个
希望得到如下结构。
              country    code       value
jan1996    US         1111       2344
                 US         1224      498
                 UK         1232      34343

feb1996  
...........

dec2012
因为初学Stata,自己用reshape命令试了好多次都没有成功。希望有高手教教我该怎么做。谢谢了!
二维码

扫码加我 拉你入群

请注明:姓名-公司-职位

以便审核进群资格,未注明则拒绝

全部回复
2013-8-17 08:52:25
可以一步步剪切粘贴,但是上百个,麻烦也容易出错。怎样方便解决?谢谢了!
二维码

扫码加我 拉你入群

请注明:姓名-公司-职位

以便审核进群资格,未注明则拒绝

2013-8-17 21:00:35
The following assumption is based on the following three assumptions:
1. No gaps in the time series : jan1996 to dec2012, total 204 months
2. The time series are arranged in a sequential order: jan 1996, feb1996, mar1996 ... in your original data file (assume file name: mydata.dta)
3. You have installed the user-written command "renvars" (type "findit renvars" in Stata, then follow instructions)

clear
set obs 204
gen id=_n
egen month=seq(),t(12)
egen year=seq(),b(12)
replace year=year+1995
gen ym=ym(year,month)
format ym %tmMonCCYY
drop month year
save tempdate, replace

use mydata, clear
renvars  jan1996- dec2012/ value1-value204
reshape long value, i(code) j(id)
order  id country code               //optional step
sort id country                        //optional step
merge m:1 id using tempdate,keep(match) nogen
二维码

扫码加我 拉你入群

请注明:姓名-公司-职位

以便审核进群资格,未注明则拒绝

2013-8-20 22:38:50
hplcdadong 发表于 2013-8-17 21:00
The following assumption is based on the following three assumptions:
1. No gaps in the time serie ...
谢谢。
二维码

扫码加我 拉你入群

请注明:姓名-公司-职位

以便审核进群资格,未注明则拒绝

2013-8-22 15:03:37
hplcdadong 发表于 2013-8-17 21:00
The following assumption is based on the following three assumptions:
1. No gaps in the time serie ...
不好意思再问一下,如果我的code也有重复的,does not uniquely identify the observations;该怎么修改呢?我用code 和country 生成一个新的变量d=code+country,应该可以用这个变量uniquely identify the observations了吧。我这样做是不是好的处理方式呢?请你指正。谢谢!
二维码

扫码加我 拉你入群

请注明:姓名-公司-职位

以便审核进群资格,未注明则拒绝

2013-8-22 21:12:56
yayacuiliu 发表于 2013-8-22 15:03
不好意思再问一下,如果我的code也有重复的,does not uniquely identify the observations;该怎么修改呢 ...
you can change the second part of my above syntax like this:

use mydata, clear
renvars  jan1996- dec2012/ value1-value204
egen group=group(code country)
reshape long value, i(group) j(id)
merge m:1 id using tempdate,keep(match) nogen
二维码

扫码加我 拉你入群

请注明:姓名-公司-职位

以便审核进群资格,未注明则拒绝

点击查看更多内容…
相关推荐
栏目导航
热门文章
推荐文章

说点什么

分享

扫码加好友,拉您进群
各岗位、行业、专业交流群