全部版块 我的主页
论坛 计量经济学与统计论坛 五区 计量经济学与统计软件 Stata专版
1638 4
2014-02-23
公司代码    交易类型     交易金额   交易时间
001              1                10             2008
001              2                15             2008
001              3                8               2009
001              4                12             2010
002              2                13             2009
002              4                23             2010
003              3               20              2010
如何把上面的数据变成
公司代码           交易时间    交易类型1         交易类型2           交易类型3          交易类型4
001                     2008          10                     15                         0                        0     
001                      2009          0                       0                          8                        0
001                      2010          0                       0                          0                        12
002                     2009           0                       2                           0                        0
002                     2010           0                       0                          0                        23
003                     2010           0                      0                           20                       0
后面的交易类型1、交易类型2、交易类型3、交易类型4这四个变量需要生成
在stata中怎么写命令啊?求教高手

二维码

扫码加我 拉你入群

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

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

全部回复
2014-2-23 06:40:30
you can use reshape, for example, suppose the var names are (id is string var)
id, type, amount, year

gen id_year=id+"_"+string(year)
reshape wide amount, i(id_year) j(type)
keep amount* id year
二维码

扫码加我 拉你入群

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

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

2014-2-23 10:59:54
jjjj6666 发表于 2014-2-23 06:40
you can use reshape, for example, suppose the var names are (id is string var)
id, type, amount, ye ...
我数据里面的这四个变量名分别是code、repat、sisam、year
这四个变量我都destring了


. gen code_year=code+"_"+string(year)
type mismatch
r(109);

.
. reshape wide sisam, i(sisam_year) j(repat)
variable sisam_year not found
r(111);

.
. keep sisam*code year
variable sisam*code not found
r(111);

能帮我指出是哪出错了不?
二维码

扫码加我 拉你入群

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

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

2014-2-23 22:23:19
if they are numerical type variables, then we need to use

gen id_year=string(id)+"_"+string(year)
reshape wide amount, i(id_year) j(type)
keep amount* id year
二维码

扫码加我 拉你入群

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

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

2014-2-24 19:13:47
谢谢啊,问题得到很好的解决
二维码

扫码加我 拉你入群

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

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

相关推荐
栏目导航
热门文章
推荐文章

说点什么

分享

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