使用本地宏将具有公共前缀的多个变量制成表格 [英] Tabulate multiple variables with common prefix using a local macro

查看:114
本文介绍了使用本地宏将具有公共前缀的多个变量制成表格的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有许多变量的名称以前缀indoor开头. indoor之后的内容不是数字的(这会使一切变得更简单).

I have a number of variables whose name begins with the prefix indoor. What comes after indoor is not numeric (that would make everything simpler).

我想为这些变量中的每一个列表.

I would like a tabulation for each of these variables.

我的代码如下:

local indoor indoor*  
foreach i of local indoor {  
    tab `i' group, col freq exact chi2  
}

问题是foreach命令中的indoor解析为indoor*,而不是我希望的indoor问题列表.因此,tab命令后跟的变量太多(它只能处理两个),这会导致错误.

The problem is that indoor in the foreach command resolves to indoor* and not to the list of the indoor questions, as I hoped. For this reason, the tab command is followed by too many variables (it can only handle two) and this results in an error.

简单的解决方法是将第一个命令替换为:

The simple fix is to substitute the first command with:

local indoor <full list of indoor questions>

但这是我要避免的事情,那就是必须找到这些变量的所有名称,然后将它们粘贴到代码中.看来有一个更快的解决方法,但是我想不到任何解决方法.

But this is what I would like to avoid, that is to have to find all the names for these variables and then paste them in the code. It seems there is a quicker fix for this but I can't think of any.

推荐答案

您可以使用

foreach i of var `indoor' {
   tab `i' group, col freq exact chi2
}

这篇关于使用本地宏将具有公共前缀的多个变量制成表格的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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