Bookmark and Share

Notice: On March 31, it was announced that Statalist is moving from an email list to a forum. The old list will shut down on April 23, and its replacement, statalist.org is already up and running.


[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: st: Problem with merging 2 datasets


From   Maarten buis <maartenbuis@yahoo.co.uk>
To   statalist@hsphsun2.harvard.edu
Subject   Re: st: Problem with merging 2 datasets
Date   Mon, 14 Jun 2010 07:29:47 -0700 (PDT)

--- On Mon, 14/6/10, Thomas Gericks wrote:
> I have a data set "A" containing economic data for each
> quarter between 1960 and 2010. Another data set "B" contains
> the quarterly results between 1960 and 2010 of 5 different
> companys.
> 
> From the manual for the command "merge" I conclude that I
> want to do merge A and B as a 1:m relationship.
> Unfortunately the dd.mm.yyyy dates in "A" (31.03.yyyy,
> 30.06.yyyy., 30.09.yyyy, 31.12.yyyy)
> are not compliant to the company dates which can be
> 27.02.yyyy instead of 31.03.yyyy. My solution is to replace
> all February dates with March, January and November with
> December, etc.

The solution would be to transform your date variable in such
a way that time is measured in quarter rather than days. This
is easily done using the -qofd()- function, see: 
-help dates_and_times- and the example below.

*------------ begin example --------------
tempfile a b
drop _all
set obs 2
gen double date = .
replace date = mdy(3,31,2010) in 1
replace date = mdy(6,30,2010) in 2
gen x1 = _n
gen long date2 = qofd(date)
save `a'

drop _all
set obs 2
gen double date = .
replace date = mdy(2,27,2010) in 1
replace date = mdy(5,26,2010) in 2
gen x1 = _n + 1
gen long date2 = qofd(date)
save `b'

merge 1:1 date2 using `a'

format date %td
format date2 %tq
list
*-------------- end example ----------------
(For more on examples I sent to the Statalist see: 
http://www.maartenbuis.nl/example_faq )

Hope this helps,
Maarten

--------------------------
Maarten L. Buis
Institut fuer Soziologie
Universitaet Tuebingen
Wilhelmstrasse 36
72074 Tuebingen
Germany

http://www.maartenbuis.nl
--------------------------


      

*
*   For searches and help try:
*   http://www.stata.com/help.cgi?search
*   http://www.stata.com/support/statalist/faq
*   http://www.ats.ucla.edu/stat/stata/


© Copyright 1996–2014 StataCorp LP   |   Terms of use   |   Privacy   |   Contact us   |   Site index