楼主: freesky521
20930 12

[其他] 怎么查找变量中的某个值 [推广有奖]

  • 5关注
  • 0粉丝

硕士生

87%

还不是VIP/贵宾

-

威望
0
论坛币
24 个
通用积分
0.0003
学术水平
2 点
热心指数
5 点
信用等级
4 点
经验
143 点
帖子
172
精华
0
在线时间
158 小时
注册时间
2009-11-6
最后登录
2019-12-3

楼主
freesky521 发表于 2012-4-3 19:52:48 |AI写论文
10论坛币
如图所示,
如图所示。 最前面的id代表的是国家代码,例如“146714” 146是Switzerland,那么714就是RWANDA。和在一起表示Switzerland向RWANDA出口2,45千万美元,在1993年的时候。那么发过来“714146”正好相反。问题就是怎么在stata中找到id(146714和714146然后在吧他们的出口值进行相加).在线等候,,重金悬赏。。期待高手来解决问题。。先谢谢了。。。图片不是很清楚。

关键词:Switzerland Stata wand Land tata 如图所示 在线 图片 国家

沙发
水木羽泉 发表于 2012-4-3 20:06:56
看来咱论坛不是一般人混得了的 都太高深了 看到点东西我就得百度查询 不过也确实学到好多东西 虽然我不懂 帮楼主捧人场~

藤椅
qiaqiao 发表于 2012-4-3 20:13:17
想法:  如果id的前3位=id的后3位, 并且 id的后3位=id的前3位,  sum(export)

板凳
hplcdadong 发表于 2012-4-3 22:25:09
Assume cty1 and cty2 are numeric variables, try the following to see if it works:

gen a=cty1+cty2
gen b=abs(cty1-cty2)
egen group=group(a b)
save temp, replace
collapse (sum) export min(id) max(id), by(group)

报纸
hplcdadong 发表于 2012-4-3 22:29:09
Sorry, should be this:

gen a=cty1+cty2
gen b=abs(cty1-cty2)
egen group=group(a b)
save temp, replace
collapse (sum) export (min) id  (max) id, by(group)

地板
hplcdadong 发表于 2012-4-4 02:37:03
OK, the last command should be:

collapse (sum) export (min) id_min=id (max) id_max=id, by(group)

7
freesky521 发表于 2012-4-4 03:48:02
hplcdadong 发表于 2012-4-4 02:37
OK, the last command should be:

collapse (sum) export (min) id_min=id (max) id_max=id, by(group)
最后的结果,出现了“type mismatch" 的错误。。。不知道是怎么回事。。
有付出总有回报。相信未来是美好的。。加油!!!

8
freesky521 发表于 2012-4-4 03:57:43
freesky521 发表于 2012-4-4 03:48
最后的结果,出现了“type mismatch" 的错误。。。不知道是怎么回事。。
You probably attempted to generate a new string variable and
        forgot to specify its type, so Stata assumed the new variable
        was to be numeric.  Include a str# before the name of the new
        variable in your generate statement.  More generally, in an
        expression you attempted to combine a string and numeric
        subexpression in a logically impossible way.  For instance,
        you attempted to subtract a string from a number or you
        attempted to take the substring of a number.
有付出总有回报。相信未来是美好的。。加油!!!

9
freesky521 发表于 2012-4-4 04:04:40
hplcdadong 发表于 2012-4-4 02:37
OK, the last command should be:

collapse (sum) export (min) id_min=id (max) id_max=id, by(group)
如果可以的话,你加我QQ:519904247 我把具体的数据给你发过去。这个问题真的是很急。今天下午5点的时候就得考试。。在这里先谢谢了。。。
有付出总有回报。相信未来是美好的。。加油!!!

10
hplcdadong 发表于 2012-4-4 04:58:09
Most likely, your "id" is a string variable, try this first:

encode id, gen (id_n)

then change the last command as follows:

collapse (sum) export (min) id_min=id_n (max) id_max=id_n, by (group)

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

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