楼主: 玄一无相
1602 5

[数据管理求助] 循环出错的问题 [推广有奖]

第一责任版主

已卖:5792份资源

学术权威

3%

还不是VIP/贵宾

-

威望
4
论坛币
48215 个
通用积分
10259.0395
学术水平
277 点
热心指数
310 点
信用等级
228 点
经验
32341 点
帖子
2688
精华
4
在线时间
3665 小时
注册时间
2010-4-7
最后登录
2025-11-28
毕业学校
郑州大学 浙江财经学院

初级学术勋章 初级热心勋章 初级信用勋章

楼主
玄一无相 在职认证  学生认证  发表于 2018-5-23 20:24:03 |AI写论文

+2 论坛币
k人 参与回答

经管之家送您一份

应届毕业生专属福利!

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

经管之家联合CDA

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

感谢您参与论坛问题回答

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

+2 论坛币

数据集(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命名数据集(不修改源数据)
二维码

扫码加我 拉你入群

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

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

关键词:implement Industry Learning earning foreach

回帖推荐

xiaojuan129 发表于4楼  查看完整内容

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,cle ...

沙发
xiaojuan129 发表于 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

藤椅
xiaojuan129 发表于 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"
}

板凳
xiaojuan129 发表于 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
已有 1 人评分经验 学术水平 热心指数 信用等级 收起 理由
玄一无相 + 100 + 2 + 2 + 2 热心帮助其他会员

总评分: 经验 + 100  学术水平 + 2  热心指数 + 2  信用等级 + 2   查看全部评分

报纸
玄一无相 在职认证  学生认证  发表于 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
谢谢

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

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