全部版块 我的主页
论坛 计量经济学与统计论坛 五区 计量经济学与统计软件 Stata专版
1547 5
2018-05-23

数据集(dta压缩)和命令如下

global vars "P0202 P0203"
foreach v of varlist $vars{
use industry.dta,clear
keep if industryclassificationid=="`v'"
drop industryclassificationid industryclassificationname
rename implementdate `v'date
rename industrycode `v'code
rename industryname `v'name
drop symbol
save "E:\stata15\learning\data\chinalisted\`v'.dta"
}


industry.rar
大小:(168.46 KB)

 马上下载

本附件包括:

  • industry.dta



我想实现的是,筛选部分数据,更改变量名称,最后以P0202/P0203命名数据集(不修改源数据)
二维码

扫码加我 拉你入群

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

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

全部回复
2018-5-23 20:58:47

global vars "P0202 P0203"
foreach v in $vars{
use industry.dta,clear
keep if industryclassificationid=="`v'"
drop industryclassificationid industryclassificationname
rename implementdate `v'date
rename industrycode `v'code
rename industryname `v'name
drop symbol
save "E:\stata15\learning\data\chinalisted\`v'.dta"
}
原因在于你的P0202 P0203不是变量,是变量中的值,因此不能用of varlist
二维码

扫码加我 拉你入群

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

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

2018-5-23 20:59:54

global vars "P0202 P0203"
foreach v in $vars{
use industry.dta,clear
keep if industryclassificationid=="`v'"
drop industryclassificationid industryclassificationname
rename implementdate `v'date
rename industrycode `v'code
rename industryname `v'name
drop symbol
save "E:\stata15\learning\data\chinalisted\`v'.dta"
}
二维码

扫码加我 拉你入群

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

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

2018-5-23 21:01:06

global vars "P0202 P0203"
foreach v in $vars{
use industry.dta,clear
keep if industryclassificationid=="`v'"
drop industryclassificationid industryclassificationname
rename implementdate `v'date
rename industrycode `v'code
rename industryname `v'name
drop symbol
save "E:\stata15\learning\data\chinalisted\`v'.dta"
}

global vars "P0202 P0203"
foreach v in $vars{
use industry.dta,clear
keep if industryclassificationid=="`v'"
drop industryclassificationid industryclassificationname
rename implementdate `v'date
rename industrycode `v'code
rename industryname `v'name
drop symbol
save "E:\stata15\learning\data\chinalisted\`v'.dta"
}
原因在于 P0202 P0203不是变量,只变量值,因此不能用of varlist
二维码

扫码加我 拉你入群

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

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

2018-5-29 11:32:35
WeChat Image_20180529113026.png
我就很纳闷,为啥会这样报错,我设定的地址有问题?
我看了下,dta并不是产生在E:\stata15\learning\data\chinalisted,而是E:\stata15\learning\data\,产生的名称叫chinalisted`v',可是我命令中间,明明有些\啊
二维码

扫码加我 拉你入群

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

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

2018-5-29 11:32:57
xiaojuan129 发表于 2018-5-23 21:01
global vars "P0202 P0203"
foreach v in $vars{
use industry.dta,clear
谢谢
二维码

扫码加我 拉你入群

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

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

栏目导航
热门文章
推荐文章

说点什么

分享

扫码加好友,拉您进群
各岗位、行业、专业交流群