Gayatri,
Stata is good at doing these things.
I am sure there are many other ways to do that, but I believe this works:
sort hh var3
qui by hh : gen temp = -1*(_n==1) + (var2==var3[1]) /* put the 'target'
obs. on top, and the 'donor' at bottom */
sort hh temp
qui by hh : gen var4 = var1[_N] if _n==1
Hope this helps,
Philippe
******************
st: merging variables within groups
From: [email protected]
Subject: st: merging variables within groups
Date: Tue, 27 May 2003 00:58:24 -0400 (EDT)
Hello,
I have a dataset which includes three variables as follows:
var 1 2 3
hhd1 a n o
hhd1 b o .
hhd2 c p r
hhd2 d q .
hhd2 e r .
hhd3 f s o
hhd3 g o .
.
.
.
.
that is, variable 2 and 3 share common values (like an id variable), with
some missing values for variable 3. i would like to create a fourth
variable
which gives the value for variable 1 (originally in the same row as the
observation variable 2) in the same row as the observation for variable 3:
var 1 2 3 4
hhd1 a n o b
hhd1 b o . .
hhd2 c p r e
hhd2 d q . .
hhd2 e r . .
hhd3 f s o g
hhd3 g o . .
but since the common 'id' variable may be the same for different
individuals
across households, i also wanted to correct for that when matching columns
3
and 2 (so that 'g' does not get matched to household 1 instead of
household
3). is there a way to join these two functions together in Stata?
Thank you very much,
Gayatri Koolwal
**********************************************************************
This email and any files transmitted with it are confidential and
intended solely for the use of the individual or entity to whom they
are addressed. If you have received this email in error please notify
the system manager.
This footnote also confirms that this email message has been swept by
for the presence of computer viruses.
**********************************************************************
*
* 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/