Statalist


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

st: RE: -varlist- using char[]?


From   "Nick Cox" <[email protected]>
To   <[email protected]>
Subject   st: RE: -varlist- using char[]?
Date   Fri, 14 Nov 2008 12:51:39 -0000

Johannes Geyer has already pointed you to -ds-, which I think is a
positive answer to your problem. I can't resist saying that in the time
since I added selection according to characteristics to -ds- I can't
recollect anyone wanting it, but the first example is especially
welcome. 

A basic problem with your -if- syntax is that -if- as a qualifier with
commands like -summarize- always acts to selects observations from a
dataset. It can never be used to select variables. 

Nick 
[email protected] 

Jeph Herrin

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
     variables.

  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:
*   http://www.stata.com/help.cgi?search
*   http://www.stata.com/support/statalist/faq
*   http://www.ats.ucla.edu/stat/stata/



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