Statalist


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

st: Merge Question


From   "Lektzian, David" <[email protected]>
To   <[email protected]>
Subject   st: Merge Question
Date   Thu, 29 May 2008 16:48:24 -0500

Dear Statalisters:
I am having a problem and could use some help merging two datasets

I'm sure there is probably an easy answer to this, but I can't think of
it.  Here is the info I think you might need to help me:

Dataset 1 -1.dta- has country, leader, and year.  These variables are
all numeric codes.  This data set also has the precise date when a
leader was removed and replaced by another leader.  Sometimes there are
also gaps where one leader has departed and the next leader has not yet
come to power.  Here is a made up example of what 1.dta looks like:
Country   leader   year	     leader start   Leader end        Obs. Start
Obs. End 
2	    25	 1960     Jan 1, 1950	  Mar 6, 1960      Jan 1, 1960
Mar 6, 1960
2	    26	 1960     Mar 7, 1960     Nov 1, 1960      Mar 7, 1960
Nov 1, 1960
2	    27	 1960     Nov 30, 1960    Jan 1, 1965      Nov 30 1960
Dec 31, 1960
2	    27	 1961     Nov 30, 1960    Jan 1, 1963      Jan 1, 1961
Dec 31, 1961	
2	    27	 1962     Nov 30, 1960    Jan 1, 1963      Jan 1, 1962
Dec 31, 1962	

Dataset 2 -2.dta- has country, year, and the precise date that a dispute
ended.  But no leader information.  Also all numeric.  
Country   year	 dispute end       
2	    1960     Mar 4, 1960	       
2         1960     Oct 27, 1960

I can merge the data on country and year and all of the disputes endings
will be assigned to the proper country and year, but when a leader
changes in the middle of the year, the dispute ending would be merged in
multiple times.  I could go into the data after the merge and delete out
all the merged information if dispute end is not between Obs. Stare and
Obs. End, but that seems kind of messy.  So I guess I am trying to merge
a precise date into the proper range of dates.

What I think I want to do is something like this:
merge country year if disputeend>obsstart & disputeend<obsendate


But I think that you cannot use an if statement in a merge.  Does
anybody have a suggestion on how to best accomplish this merge?

Thanks,
Dave

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