Dear Stata Community,
I am very sorry if this question is rather basic, but I am desperately seeking help for my master's thesis. Attached is a sample of my dataset.
What I need to find out is: per fund id : how many observations are there between the actual monthnum[_n] and monthnum[_n]-36. In other words, as my panel is not balanced, I need to define the time window for a rolling 36-month regression (the rolling command is way too slow, as my dataset contains 1m+ observations).
I tried the following code:
foreach i in id {
forval j = 204/395 {
egen temp = count(monthnum) if monthnum >= (`j'-36) & monthnum <=`j' & id == `i'
replace count_id = temp if monthnum == `j'
drop temp
}
}
but somehow it does not properly count the number of observations, and simply adds 74 for all values....
can you please help me with this issue?
Thank you so much for helping an unexperienced stataist!
I am very sorry if this question is rather basic, but I am desperately seeking help for my master's thesis. Attached is a sample of my dataset.
What I need to find out is: per fund id : how many observations are there between the actual monthnum[_n] and monthnum[_n]-36. In other words, as my panel is not balanced, I need to define the time window for a rolling 36-month regression (the rolling command is way too slow, as my dataset contains 1m+ observations).
I tried the following code:
foreach i in id {
forval j = 204/395 {
egen temp = count(monthnum) if monthnum >= (`j'-36) & monthnum <=`j' & id == `i'
replace count_id = temp if monthnum == `j'
drop temp
}
}
but somehow it does not properly count the number of observations, and simply adds 74 for all values....
can you please help me with this issue?
Thank you so much for helping an unexperienced stataist!
Comment