
From  Kyle Hood <kyle.hood@yale.edu> 
To  statalist@hsphsun2.harvard.edu 
Subject  Re: st: Create String Variable out of Variable Names 
Date  Wed, 25 Oct 2006 18:25:50 0400 (EDT) 
I have a set of variables that I would like to use to generate a singular String variable. The number of cases in each resulting value is inconsequential.
So for example if I had 5 variables (a b c d e) in a data set with 100 observations I would like a String variable that looked something like:
Var  Frequency
a 20
b 20
c 20
d 20
e 20
Now I know that in this simple case I could do this line by line with:
egen var = seq(), f(1) t(5)
replace var = "a" if var==1
replace var = "b" if var==2
...
But in the case of 64 variables this is unrealistically tedious, especially as I am hoping to incorporate this into a more encompassing program to be used with different sets of variables.
The problem I've run into with foreach is that it loops so that in the end the resulting variable looks like (using the example from above).
Var  Freq
e 100
[Also note that the variables are not mutually exclusive (ala dummies), so that a case could ==1 on several of the variables]
Any help with this would be greatly apprecaited,
Thank you,
Kyle C. Longest
Phd Student  Dept of Sociology
Univ. of North Carolina  Chapel Hill
klongest@email.unc.edu
*
* For searches and help try:
* http://www.stata.com/support/faqs/res/findit.html
* http://www.stata.com/support/statalist/faq
* http://www.ats.ucla.edu/stat/stata/
* * For searches and help try: * http://www.stata.com/support/faqs/res/findit.html * http://www.stata.com/support/statalist/faq * http://www.ats.ucla.edu/stat/stata/
© Copyright 1996–2015 StataCorp LP  Terms of use  Privacy  Contact us  What's new  Site index 