Bookmark and Share

Notice: On March 31, it was announced that Statalist is moving from an email list to a forum. The old list will shut down on April 23, and its replacement, statalist.org is already up and running.


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

st: alphabet range


From   Bernie Hogan <bernie.hogan@gmail.com>
To   statalist <statalist@hsphsun2.harvard.edu>
Subject   st: alphabet range
Date   Tue, 28 Sep 2010 13:27:06 +0100

Hi everyone,

I have dyadic data, with many matrix questions (i.e. ranges of similar
questions for both people).

The data are structured like so
q[number][letter][f/s]  such as

q17af

where 17 is the matrix, a is the row, and f is the first person to
respond, s is the second.

I would like to be able to do calculations on the entire row. The best
I could come up with was:

local vlist a b c d e f g h i

foreach var of local vlist {
 	gen dsq17`var' = q17`var'f - q17`var's
}

But that means every time I do a new matrix I have to figure out how
many variables, and then type out their letter by hand.

What I would really like is to be able to say:

foreach var of q17? [f or s] {
gen newvar = q17?f - q17?s
}
(or whatever is the closest to that)

…but I'm having trouble taking the varname and replacing it with
another character and evaluating them together or creating
programmatically a range of characters. Any suggestions on how to
clean up that code?

Take care,
BERNiE

Dr Bernie Hogan
Research Fellow, Oxford Internet Institute, University of Oxford
http://people.oii.ox.ac.uk/hogan/

*
*   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–2014 StataCorp LP   |   Terms of use   |   Privacy   |   Contact us   |   Site index