楼主: wan68g
1637 4

[数据管理求助] 怎么生产变量 [推广有奖]

  • 1关注
  • 0粉丝

大专生

26%

还不是VIP/贵宾

-

威望
0
论坛币
24 个
通用积分
0
学术水平
0 点
热心指数
0 点
信用等级
0 点
经验
527 点
帖子
36
精华
0
在线时间
14 小时
注册时间
2012-10-22
最后登录
2015-4-9

楼主
wan68g 发表于 2014-2-23 00:25:58 |AI写论文

+2 论坛币
k人 参与回答

经管之家送您一份

应届毕业生专属福利!

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

经管之家联合CDA

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

感谢您参与论坛问题回答

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

+2 论坛币
公司代码    交易类型     交易金额   交易时间
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中怎么写命令啊?求教高手

二维码

扫码加我 拉你入群

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

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

关键词:Stata 交易类型 交易时间 tata 如何

沙发
jjjj6666 发表于 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

藤椅
wan68g 发表于 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);

能帮我指出是哪出错了不?

板凳
jjjj6666 发表于 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

报纸
wan68g 发表于 2014-2-24 19:13:47
谢谢啊,问题得到很好的解决

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

本版微信群
加好友,备注jltj
拉您入交流群
GMT+8, 2026-2-1 04:02