Notice: On April 23, 2014, Statalist moved from an email list to a forum, based at statalist.org.
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: st: Merging w/ substituting for years with missing values
From
"James Beard" <[email protected]>
To
[email protected]
Subject
Re: st: Merging w/ substituting for years with missing values
Date
Sat, 03 Aug 2013 10:40:11 +0545
Another interpretation of the question would be "how to do the
merge". This can be acheived by using -expand- on the A dataset to
(say) produce (a total of) 5 records for each original record, then
merging this dataset with B on year and doing the -carryforward-.
* on dataset A
gen original_year = year
expand 5
sort original_year
by original_year: replace year = year - 3 + _n
Then use -merge- and -carryforward- as appropriate and finally drop
the records with year!=original_year. Because there may now be
duplicates on year, the merge would probably need to be m:1.
On Fri, 02 Aug 2013 12:44:48 -0400, David Kantor wrote:
It's not too hard to write code to do that, but you may want to try
carryforward from SSC. It goes forward, but you can use a negative
date to trick it into gong backward. For filling inward, I like to do
both forward and back, and see if the values agree.
HTH
--David
At 11:24 AM 8/2/2013, Leoni wrote:
I'm merging two panel datasets (A and B), one of which has few years
(A, I only need those), while the other has observations for many
years (B) -- but also has missing values for some of them. As most of
the variables that have missing values don't change a lot, I want to
tell STATA to use values from previous or following years (from B) if
they're missing for the exact year I need (those in A). This sounds
rather messy but is there an elegant way of doing this in STATA?
Any help is much appreciated.
Leoni
*
* For searches and help try:
* http://www.stata.com/help.cgi?search
* http://www.stata.com/support/faqs/resources/statalist-faq/
* http://www.ats.ucla.edu/stat/stata/
*
* For searches and help try:
* http://www.stata.com/help.cgi?search
* http://www.stata.com/support/faqs/resources/statalist-faq/
* http://www.ats.ucla.edu/stat/stata/