楼主: liyan_m1
2872 11

[其他] 请问stata高手,怎么转换下面的数据 [推广有奖]

  • 2关注
  • 0粉丝

已卖:1份资源

博士生

3%

还不是VIP/贵宾

-

威望
0
论坛币
5 个
通用积分
7.1441
学术水平
0 点
热心指数
0 点
信用等级
0 点
经验
2104 点
帖子
94
精华
0
在线时间
315 小时
注册时间
2011-2-18
最后登录
2025-10-4

楼主
liyan_m1 发表于 2012-3-16 23:31:51 |AI写论文

+2 论坛币
k人 参与回答

经管之家送您一份

应届毕业生专属福利!

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

经管之家联合CDA

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

感谢您参与论坛问题回答

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

+2 论坛币
怎么讲下面的的数据
firm    product    destination     value                           
1             1               1                7
1             2               3                8
2             1               2                 9
3             3               4                 4
3             4               1                  5

转换成

firm    product    destination     value
1             1               1                7
1             1               3                 0
1             2               3                8
1             2               1                 0
2             1               2                 9
3             3               4                 4
3             3               1                  0
3             4               1                  5
3             4                4                  0


谢谢!!
二维码

扫码加我 拉你入群

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

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

关键词:Stata tata destination Product Nation product

沙发
liyan_m1 发表于 2012-3-16 23:40:25
就是把企业的潜在出口国补全,潜在国就是该企业总共的出口国
患己不知

藤椅
bwhbwh 发表于 2012-3-17 01:08:04

一个笨办法

笨办法,针对上述格式:
expandcl 2, generate(newcl) cluster( firm )


. bys firm:gen m=_n

. replace va=0 if m==2|m==4

. drop  newcl

. gen w= de

. replace w=de[_n+2] if  m==2

. ge w1=de

. replace w1=de[_n-2] if  m==4


. replace de=w if m==2


. replace de=w1 if m==4


. drop  w1 w

. bys firm :ge m1=_N
drop if m==2&m1=2

板凳
famousid 发表于 2012-3-17 10:29:43
sort firm product
解决不了吗?

报纸
liyan_m1 发表于 2012-3-17 13:55:57
bwhbwh 发表于 2012-3-17 01:08
笨办法,针对上述格式:
expandcl 2, generate(newcl) cluster( firm )
这样的转换也不对,因为第2个企业只出口了一种产品,所以是不要扩张的,而且在数据很多,产品和国家都很多的时候,这样的方法不好用。。不过还是很谢谢
患己不知

地板
liyan_m1 发表于 2012-3-17 13:56:36
famousid 发表于 2012-3-17 10:29
sort firm product
解决不了吗?
我不是要排序,而是要扩展数据
患己不知

7
bwhbwh 发表于 2012-3-17 23:45:46
期待斑竹,

8
hplcdadong 发表于 2012-3-18 03:43:05
This is a little bit tricky one, but can be solved as follows:

save the original data as "test.dta"

use test, clear
keep firm product
save product, replace

use test, clear
keep firm destination
save destination, replace

joinby firm using product
merge 1:1 firm product destination using test
drop _merge
sort firm product destination value
list          //you are all set

9
flyawaykai 在职认证  发表于 2012-3-18 11:58:59
修改一下楼上的程序
use test, clear
keep firm product
save product, replace

use test, clear
keep firm destination
save destination, replace

joinby firm using product
sort firm product
duplicates drop
merge 1:m firm product destination using test
drop _merge
replace value=0 if value==.
sort firm product destination value

10
liyan_m1 发表于 2012-3-18 12:13:04
flyawaykai 发表于 2012-3-18 11:58
修改一下楼上的程序
use test, clear
keep firm product
非常感谢。。。。
患己不知

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

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