楼主: lurunjing
4410 6

[数据管理求助] STATA 求助:如何有效率的把string转化成特定的code [推广有奖]

  • 0关注
  • 0粉丝

高中生

72%

还不是VIP/贵宾

-

威望
0
论坛币
0 个
通用积分
0
学术水平
0 点
热心指数
0 点
信用等级
0 点
经验
224 点
帖子
51
精华
0
在线时间
14 小时
注册时间
2011-5-17
最后登录
2016-2-25

楼主
lurunjing 发表于 2015-7-8 07:22:54 |AI写论文

+2 论坛币
k人 参与回答

经管之家送您一份

应届毕业生专属福利!

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

经管之家联合CDA

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

感谢您参与论坛问题回答

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

+2 论坛币
我的数据里面有大量的国家名字(string), 我想把这些名字根据特定的country-code list 都转化成特定的country code (string 或者numeric都行),以便于与另外的dataset 作merge.
我stata很初级,只能想到用if 语句,一个一个对比country name 和对应的country code,在生成新的string var。但这个特别慢啊,请问用什么command比较有效率?
二维码

扫码加我 拉你入群

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

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

关键词:string Stata tring tata RING command country 如何 国家

沙发
hustchen2012 在职认证  发表于 2015-7-8 22:48:27
  1. gen country=0
  2. replace county=1 if strmatch(country_name,"*China*")
  3. replace county=2 if strmatch(country_name,"*U.S*")
复制代码

藤椅
夏目贵志 发表于 2015-7-9 01:40:53
也可以用label。例如
  1. #delimit ;
  2. label define agegroup
  3.         1 "Up to 25 years"
  4.         2 "25 to 30 years"
  5.         3 "30 to 35 years"
  6.         4 "35 to 40 years"
  7.         5 "40 to 45 years"
  8.         6 "45 to 50 years"
  9.         7 "50 to 55 years"
  10.         8 "55 to 60 years"
  11.         9 "60 years and above";
  12. #delimit cr
  13. label values agegroup agegroup
复制代码

板凳
wb103 在职认证  发表于 2015-7-9 02:49:23
egen country_id=group(trim(country name))
sum country_id

报纸
夏目贵志 发表于 2015-7-9 03:44:49
wb103 发表于 2015-7-9 02:49
egen country_id=group(trim(country name))
sum country_id
这样就不能用现有的定义好的country code list了。不过如果不用使用现成的list这个办法还是很好的。

地板
wb103 在职认证  发表于 2015-7-9 09:21:48
夏目贵志 发表于 2015-7-9 03:44
这样就不能用现有的定义好的country code list了。不过如果不用使用现成的list这个办法还是很好的。

7
lurunjing 发表于 2015-7-10 05:43:31
谢谢 各位的帮助!!!!

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

本版微信群
加好友,备注jltj
拉您入交流群
GMT+8, 2026-1-1 02:45