[Date Prev][Date Next][Thread Prev][Thread Next][Date index][Thread index]
st: merging variables within groups
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,
* For searches and help try: