本站分享:AI、大数据、数据分析师培训认证考试,包括:Python培训Excel培训Matlab培训SPSS培训SAS培训R语言培训Hadoop培训Amos培训Stata培训Eviews培训

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

stata培训 cdadata 12320℃

怎么查找变量中的某个值

怎么查找变量中的某个值

最前面的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培训

喜欢 (1)or分享 (0)