Bookmark and Share

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: Obtain information from nearest observation


From   Jeph Herrin <[email protected]>
To   [email protected]
Subject   Re: st: Obtain information from nearest observation
Date   Fri, 07 Sep 2012 14:36:07 -0400

********* this should do it **************************************
u datasetA, clear
ren EVENT_DATE DATE
gen byte event=1
merge 1:m COMPANY using datasetB, keepusing(DATE NET_SALES)
drop if _merge==2
bysort COMPANY (DATE) : egen last_sales=NET_SALES[_n-1] if event==1
bysort COMPANY (DATE) : egen next_sales=NET_SALES[_n+1] if event==1


On 9/7/2012 11:54 AM, "Marco Müller" wrote:
Hi all

I have the following problem: I have a dataset A with event dates for firms as:
COMPANY    EVENT_DATE
1          01/03/1986
2          15/08/2001


and I have a dataset B with financial information about the firms, e.g.:
COMPANY     DATE             NET_SALES
1           31/12/1985       1'000
1           31/12/1986       2'000
1           31/12/1987       1'200
....
2           30/06/2000         400
2           30/06/2001         600
2           30/06/2002         700

I'd like to obtain the last available net sales information PRIOR to the event date (or, in another case, the first one FOLLOWING the event date). For example, I'd like to obtain the net sales of 1'000 and 600 for A and B (prior to the events) and 2'000&700 following the events.

Any suggenstions how to handle that?

Many thanks for your suggestions

Best regards,
Marco
*
*   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/


*
*   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–2018 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   Site index