Stata The Stata listserver
[Date Prev][Date Next][Thread Prev][Thread Next][Date index][Thread index]

st: Re: two-year panel, combining datasets


From   baum <[email protected]>
To   [email protected]
Subject   st: Re: two-year panel, combining datasets
Date   Sun, 11 Aug 2002 09:26:24 -0400

--On Sunday, August 11, 2002 2:33 -0400 Andres ([email protected]) wrote:

panel.dta
obsid	year
1	2000
2	2000
3	2001
4	2001

obsidpairs.dta
year2000	year2001
1	3

I would like to end up with
obsid	year	hhid
1	2000	1
2	2000	2
3	2001	1
4	2001	4
You do not give the second record in the 'pairs' dataset, but I presume it should be '2 4' -- which as I understand it would imply that the last element in 'hhid' above should be '2', not '4'. This will achieve that:

clear
input obsid year
1 2000
2 2000
3 2001
4 2001
end
sort obsid
save panel,replace
clear
input obs2000 obs2001
1 3
2 4
end
sort obs2001
save pairs,replace
use panel
rename obsid obs2001
merge obs2001 using pairs
replace obs2000 = obs2001 if _merge==1
drop _merge
rename obs2001 hhid
rename obs2000 obsid
sort hhid
list


Kit

*
* 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