Statalist


[Date Prev][Date Next][Thread Prev][Thread Next][Date index][Thread index]

st: RE: Creating a new variable by combining several


From   "Nick Cox" <[email protected]>
To   <[email protected]>
Subject   st: RE: Creating a new variable by combining several
Date   Tue, 5 Feb 2008 21:43:52 -0000

There is some mismatch of example and discussion here but I think this
is what you mean here. 

gen byte whichage = . 
qui forval i = 1/4 { 
	replace whichage = `i' if age`i' == 1 
} 

OR 

gen byte whichage = age1 + 2 * age2 + 3 * age3 + 4 * age4 

Nick 
[email protected] 

-----Original Message-----
From: [email protected]
[mailto:[email protected]] On Behalf Of sara khan
Sent: 05 February 2008 21:36
To: [email protected]
Subject: st: Creating a new variable by combining several

Dear Statalisters

I would be most gratfeul if someone could advise me on the following:

I am working with long data and need to create a variable that
summarises information from several categorical variables. For
example, for the variables hdage1-hdage4, I want to create a single
variable that tells me which category each pid belongs to (the
opposite of the command (ta var, ge(var*) )) . Thus, for the first
person, I want a variable that lists age3 at each wave, for the second
age3 in the same variable etc.

Any help would be most apprecaited.

Regards

Sara


	+-----------------------------------------------------+
	pid            wave    age1   age2   age3   age4
	-----------------------------------------------------
22.	10014608      1        0        0        0        1
23.	10014608      2        0        0        0        1
24.	10014608      3        0        0        0        1
25.	10014608      6        0        0        0        1
26.	10014608      8        0        0        0        1
27.	10014608      9        0        0        0        1
28.	10014608     10        0        0        0        1
29.	10014608     12        0        0        0        1
	-----------------------------------------------------
30.	10016813      2        0        0        1        0
31.	10016813      4        0        0        1        0
32.	10016813      9        0        0        1        0

*
*   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–2024 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   What's new   |   Site index