楼主: yayacuiliu
2405 6

[编程问题求助] 数据结构变化 [推广有奖]

  • 0关注
  • 0粉丝

硕士生

22%

还不是VIP/贵宾

-

威望
0
论坛币
4 个
通用积分
2.0004
学术水平
1 点
热心指数
1 点
信用等级
1 点
经验
2817 点
帖子
87
精华
0
在线时间
158 小时
注册时间
2008-9-16
最后登录
2024-9-27

楼主
yayacuiliu 发表于 2013-8-16 23:25:52 |AI写论文

+2 论坛币
k人 参与回答

经管之家送您一份

应届毕业生专属福利!

求职就业群
赵安豆老师微信:zhaoandou666

经管之家联合CDA

送您一个全额奖学金名额~ !

感谢您参与论坛问题回答

经管之家送您两个论坛币!

+2 论坛币
数据结构变化。
数据举例如下:
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命令试了好多次都没有成功。希望有高手教教我该怎么做。谢谢了!
二维码

扫码加我 拉你入群

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

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

关键词:结构变化 数据结构 Country reshape Count country 9000

沙发
yayacuiliu 发表于 2013-8-17 08:52:25 来自手机
可以一步步剪切粘贴,但是上百个,麻烦也容易出错。怎样方便解决?谢谢了!

藤椅
hplcdadong 发表于 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
已有 1 人评分经验 论坛币 学术水平 热心指数 信用等级 收起 理由
Sunknownay + 100 + 8 + 1 + 1 + 1 热心帮助其他会员

总评分: 经验 + 100  论坛币 + 8  学术水平 + 1  热心指数 + 1  信用等级 + 1   查看全部评分

板凳
yayacuiliu 发表于 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 ...
谢谢。

报纸
yayacuiliu 发表于 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了吧。我这样做是不是好的处理方式呢?请你指正。谢谢!

地板
hplcdadong 发表于 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

7
yayacuiliu 发表于 2013-8-22 23:06:19
hplcdadong 发表于 2013-8-22 21:12
you can change the second part of my above syntax like this:

use mydata, clear
谢谢你了!我又学到了一个好办法!

您需要登录后才可以回帖 登录 | 我要注册

本版微信群
加好友,备注jltj
拉您入交流群
GMT+8, 2025-12-29 13:56