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

st: RE: RE: Variable generation

From   "Mentzakis, Emmanouil" <>
To   <>
Subject   st: RE: RE: Variable generation
Date   Mon, 11 Feb 2008 19:38:19 -0000

Dear Nick, 

Thank you


-----Original Message-----
[] On Behalf Of Nick Cox
Sent: 11 February 2008 17:45
Subject: st: RE: Variable generation

bysort hid (var1) : gen var2 = var1[1] 

For more detail, see 

FAQ    Replacing missing values
How can I replace missing values with previous or following nonmissing

Your problem is only a twist away from that discussed in the FAQ. 

However, in general you need to check that each -hid- is characterised
by at most one non-missing value on -var1-. See also 

FAQ Number of distinct observations
How do I compute the number of distinct observations?


Mentzakis, Emmanouil

I have a variable that identifies the household (hid), a variable that
identifies the number that each individual has within the household
(pid) and finally a variable that has some values of interest (present
only for some individuals).

I would like to create a new variable (var2) that has the value of var1
for all the pid in the same hid (as in the example below).

hid	pid	var1	var2        
1	1	10	10           
1	2		10               
2	1		6              
2	2	6	6            
2	3	6	6             
2	4		6              
3	4	8	8                 
3	5		8	               

One way to do it is:  
by hid: egen var2=mean(var1)   

However, I was wondering if there was any command that rather than
taking averages, could copy that value to everybody with the same hid.

*   For searches and help try:

*   For searches and help try:

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