在stata中的do-file中将命令分成几行 [英] Break a command into several lines in do-file in Stata

查看:4390
本文介绍了在stata中的do-file中将命令分成几行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想这是一个平凡的问题,但我找不到帮助。我想在Stata 12中的一个文件中运行 keep 命令:

I guess this is a trivial question but I can't find help on it. I want to run the keep command in a do-file in Stata 12:

keep a1 a2 a3 a4 a5 b1 b2 b3 b4 b5 c1 c2 c3 c4

,在我的代码中我使用了大约一百个变量,而不只是14作为上面的例子。)我想要的是做以下:

(In fact, in my code I use around a hundred variables, not just 14 as the example above.) What I want is to do the following:

keep {a1 a2 a3 a4 a5
     b1 b2 b3 b4 b5
     c1 c2 c3 c4}

我知道{}括号不会做的伎俩,但我正在寻找这样做的命令。使用 #delimiter; 也不工作。

I know the {} brackets don't do the trick but I'm looking for the command that does it. Using #delimiter ; does not work either.

我想这样做是因为变量的子组之间有一个关系(我打算用 a b c ),我想在我的代码清楚。我永久添加和删除变量。注意,我不想使用 drop 命令(在这种情况下解决方案是微不足道的)。

I want to do this because subgroups of variables have a relation among themselves (which I intended to signal above by using a, b and c) and I want to have that clear in my code. I permanently add and delete variables. Note that I don't want to use the drop command (in which case the solution is trivial).

推荐答案

这只是一个非常简单的技巧来补充Roberto的真正解决方案。因为你有这么多的变量,我发现有时候有用的是使用宏来分组变量,特别是如果你可以在多个场合使用分组。

This is just a very simple trick to complement the real solutions by Roberto. Since you have so many variables, one thing I found sometimes useful is to use macros to group variables, especially if you can use the grouping in more than one occasion.

loca a a1 a2 a3 a4 a5
loca b b1 b2 b3 b4 b5
loca c c1 c2 c3 c4 c5
keep `a' `b' `c'

这篇关于在stata中的do-file中将命令分成几行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆