全部版块 我的主页
论坛 计量经济学与统计论坛 五区 计量经济学与统计软件 Stata专版
1144 1
2012-07-30
数据如下:id        country        staffnumber       
900810        all        5       
900810        BGR        3       
900810        PRK        2       
900810        SGP        7       
900912        all        5       
900912        BGR        1       
900912        CHN        3       
900912        MYS        4       
900912        PRK        3       
900912        SGP        9       



all指所有国家在内.
参考第一个公司(id)它除了有all,还有3个国家,所以要生成一个变量,需要all中的staffnumber加上各个国家的(all的不便),例如900810在BGR的员工总数应该为:5+3=8,在prk的应该为5+2=7.最后产生的变量需要如下:
id        country        staffnumber        totalnumber
900810        all        5                         5
900810        BGR        3                         8
900810        PRK        2                         7
900810        SGP        7                       12       
900912        all        2                         2
900912        BGR        1                         3
900912        CHN        3                       5       
900912        MYS        4                       6       
900912        PRK        3                         5
900912        SGP        9                       11


应该怎么做呢?
多谢
二维码

扫码加我 拉你入群

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

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

全部回复
2012-7-30 02:27:00
自己回答一下哈^^,请指正,貌似可以做


gen dummy=1 if country!="all"
replace dummy=0 if country=="all"
by id: egen all_no=max(staffmuber)
gen totalstaffnumber=all_no+staffnumber if dummy==1
replace totalstaffnumber=staffnumber if dummy==0
二维码

扫码加我 拉你入群

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

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

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

说点什么

分享

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