Quantcast
Channel: Statalist
Viewing all articles
Browse latest Browse all 72758

count of experiences using a moving 5yr window

$
0
0
Hello!
I am working with data on M&A.
I am trying to calculate the number of times a certain type of acquisition experience (coded as a dummy) occurs but only when it occurs within 5 years prior to the focal deal.
For example:
firm_id laggains announcedyear count_sg
1 0 1989 0
1 1 1994 1
1 1 1998 2
1 1 2000 2
1 0 2001 2
1 0 2003 2
1 1 2004 2
2 1 1999 1
2 0 2000 1
2 0 2001 1
2 0 2002 1
2 1 2003 2
2 1 2005 2
where laggains is the type of experience (dummy variable), announcedyear is the year that the experience occured and count_sg is the variable I would like to create.
(count_sg=the total number of times laggains occured within the 5 yrs prior to announcedyear)
(fyi, the variable laggains is a lagged variable so it is actually missing for the very first observation of each firm_id)

Based on Stata Tip 51: http://www.stata-journal.com/sjpdf.h...iclenum=pr0033

i tried the following code in Stata/SE 12.1

:
gen count_sg=.
quietly forval i=1/'=_N' {
count if inrange(lagsmallg5d_h, 1, .)  &
inrange(announcedyear['i']-announcedyear, 1, 5)
replace count_sg=r(N) in 'i'
but i get invalid syntax r(198)

any suggestions/ideas as to what is wrong how I can generate the count_sg variable?
Thanks in advance!

Viewing all articles
Browse latest Browse all 72758

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>