[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

st: -varlist- using char[]?

From   Jeph Herrin <>
Subject   st: -varlist- using char[]?
Date   Thu, 13 Nov 2008 16:38:00 -0500

I've a dataset with a very large number of variables
in a number of files. The variables are named according
to no apparent plan; however, I need to keep the names
for various reasons beyond my control.

So, using the data dictionary I was able to automate a process
of assigning meaningful char[] values to all of these variables.
Thus, for example, I can check if a variable came from a certain
file by checking the the char[].

This has been helpful in a lot of programming contexts.
For instance, I currently pull out the variables that form
the KCCQ survey scale by looping over ALL the variables

 foreach V of _all {
	local scale = V[scale]
	if "`scale'"=="KCCQ" {

This is awkward to say the least; more importantly, it doesn't
help me interactively if, for instance, I want to type

 . sum if char[scale]=="KCCQ"

But no variation on this syntax seems to work.

So I guess this question has two parts.

 1. Is there a direct way to create a macro which contains
    the names of all variables matching a certain characteristic?
    And by direct I suppose I mean other than looping over all

 2. Is there a way to reference such a subset interactively,
    as above?

I think the answer is no to both, but thought it worth asking.


*   For searches and help try:

© Copyright 1996–2020 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   What's new   |   Site index