全部版块 我的主页
论坛 计量经济学与统计论坛 五区 计量经济学与统计软件 Stata专版
2177 2
2015-10-21
两个命令:
一:
foreach num of numlist 0/1 {
foreach i of numlist 1/2{

*
dis _n in g "monthly200`num'0`i'" in y  "的初始缺失值数量是:" in y  `xx'
*
}
}

*
二:
foreach num of numlist 0/0 {
foreach i of numlist 1/12 {
if `i'<=2 {
local x=
do "C:\Users\miao\Desktop\others\1234.do"
   }
}
}


1234.do 内容是dis _n in g "monthly200`num'0`i'" in y  "的初始缺失值数量是:" in y  `xx'
两段命令差别在于 一个有子do文件,一个不包含子do文件。
问题是:为什么子do文件不能显示`num'和`i'暂元,是否子do文件不能使用上一级do文件的local暂元,如果是,怎么解决在子do中显示上一级的暂元?
二维码

扫码加我 拉你入群

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

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

全部回复
2015-10-22 00:31:18
从local macro这个名字就能看出来吧。这些macro只在一定的范围里有效。如果你想要在更大的范围使用,可以使用global macro;也可以把子do-file的内容写成程序,然后把需要的参数传递给这个程序。local macro适用的具体范围请看一下帮助文件。
Local macros exist solely within the program or do-file in
which they are defined. If that program or do-file calls another program or do-file, the local macros
previously defined temporarily cease to exist, and their existence is reestablished when the calling
program regains control. When a program or do-file ends, its local macros are permanently deleted.
二维码

扫码加我 拉你入群

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

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

2018-3-13 23:36:33
夏目贵志 发表于 2015-10-22 00:31
从local macro这个名字就能看出来吧。这些macro只在一定的范围里有效。如果你想要在更大的范围使用,可以使 ...
您好!看您对stata中暂元的回答比较专业,我想向您请教一个问题:就是两个暂元能相加吗?有没有命令能让两个暂元加总?或者更具体到我这个例子,就是有个两层的嵌套循环,外层i=1/10,内层j=1/3,每次内层运算都要est sto 一下,如果单用i或者j作为est sto的名称,肯定是不够的,想请问一下您能否用i和j联合起来为其命名?如果不可以的话,有没有什么其他的命名方式?谢谢您!
二维码

扫码加我 拉你入群

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

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

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

说点什么

分享

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