数据价值-DataValues

 找回密码
 立即注册

QQ登录

只需一步,快速开始

查看: 236|回复: 0

[stata] 怎么查找变量中的某个值_stata培训

[复制链接]

1万

主题

1万

帖子

3万

积分

管理员

Rank: 9Rank: 9Rank: 9

积分
39025
发表于 2016-12-12 13:00:39 | 显示全部楼层 |阅读模式
怎么查找变量中的某个值,

,
最前面的id代表的是国家代码,例如“146714” 146是Switzerland,那么714就是RWANDA。和在一起表示Switzerland向RWANDA出口2,45千万美元,在1993年的时候。那么发过来“714146”正好相反。问题就是怎么在stata中找到id(146714和714146然后在吧他们的出口值进行相加).在线等候,


解答:
想法:  如果id的前3位=id的后3位, 并且 id的后3位=id的前3位,  sum(export)


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)

,,
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),,
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),,
The following is a better one to convert the string “id” variable:,
destring id, gen (id_n1),
then change the last command as follows:,
collapse (sum) export (min) id_min=id_n1 (max) id_max=id_n1, by(group),,
刚才有试了一下。出现了r(111) error . . . . . . . . . . . . . . . . . . . . . . . .  Return code 111
__________ not found;
no variables defined;
The variable does not exist.  You may have mistyped the
variable’s name.
variables out of order;
You specified a varlist containing varname1-varname2, yet
varname1 occurs after varname2.  Reverse the order of the
variables if you did not make some other typographical error.
Remember, varname1-varname2 is taken by Stata to mean varname1,
varname2, and all the variables in dataset order in between.
Type describe to see the order of the variables in your dataset.
__________ not found in using data;
You specified a varlist with merge, yet the variables on which
you wish to merge are not found in the using dataset, so the
merge is not possible.
__________ ambiguous abbreviation;
You typed an ambiguous abbreviation for a variable in your data.
The abbreviation could refer to more than one variable.  Use a
nonambiguous abbreviation or, if you intend all the variables
implied by the ambiguous abbreviation, append a `*’ to the end
of the abbreviation.,
转载请注明:数据分析 » 怎么查找变量中的某个值_stata培训
回复

使用道具 举报

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

本版积分规则

QQ|Archiver|手机版|小黑屋|DataValues ( 赣ICP备16006919号 ) DataValues

GMT+8, 2019-6-20 07:41 , Processed in 0.105689 second(s), 29 queries .

Powered by Discuz! X3.4

© 2001-2017 Comsenz Inc.

快速回复 返回顶部 返回列表