Suppose the definition of a set of dummy variables was more complicated
than in this well-behaved example.
Say -x- takes on values 11, 13, 17, 19, 23 and dummies -x1- to -x5-
correspond to those values, i.e. -x1- is 1 iff -x- is 11, and so forth.
But of course -x- is not in your dataset; if it were you would not be
doing this.
The look-up technique could be something like this. Use -tokenize- on
the list of values to assign them to local macros 1 to 5.
tokenize "11 13 17 19 23"
gen x = .
qui forval i = 1/5 {
replace x = ``i'' if x`i' == 1
}
-----Original Message-----
From: [email protected]
[mailto:[email protected]] On Behalf Of Nick Cox
Sent: 05 February 2008 22:16
To: [email protected]
Subject: st: RE: Creating a new variable by combining several
Good. The generalisation to other sets of dummies should be clear. If
there are twenty dummies, a loop may be more congenial:
gen byte whichpet = pet1
qui forval i = 2/20 {
replace whichpet = whichpet + `i' * pet`i'
}
*
* 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/