Viewing 5 posts - 1 through 5 (of 5 total)
• Author
Posts
• Mike Stu
Guest
Post count: 118

Hi,

I am trying to calculate all rolling percentiles of all panels in the past 12 months (excluding the current month) and then assign the current observation into the respective percentiles in the past 12 months.

What would be the most efficient way to do it as I have 1.4 Million firm-month observations.

Currently my code looks like this ( as an example):

foreach x in iv v {

gen P_x'=.
forvalue i=0.01 (1) 0.99 {
loc d=i'*100
asrol  x', stat(median) perc(i') window(month_id 12) xf(focal) gen(Pd')
}
}
forvalue i=1 (1) 99 {
replace P_x'=0 ifx'<P1
replace P_x'=i' if x'>Pi' | x'==Pi' & x'<Pi'+1
replace P_x'=100 ifx'>P99
replace P_x'=. ifx'==.
}
forvalue i=1 (1) 99 {
drop Pi'
}
}


I have seen here on the website that the window option now features three arguments so w(n -13 -1) would also work but Stata does not allow it for me.
Also, the loop stops somehow after P1 so there is a mistake with loc d.

Thank you very much for your help.

best,
Mike

Attaullah Shah
Keymaster
Post count: 69

The new version is not yet uploaded to the SSC, therefore, you need to install it from my site.
The new version of asdoc can be installed from my site. Copy and paste the following line in Stata and press enter.

net install asrol, from(http://fintechprofessor.com) replace

Please note that the above line has to be copied in full. After installation of the new version, then restart Stata.

For rolling percentiles with for several variables, there is no need to use loop, you can specify many variables with asrol.

asrol iv v , stat(median) perc(.1) window(month_id -12 -1)
asrol iv v , stat(median) perc(.99) window(month_id -12 -1) 
Mike Stu
Guest
Post count: 118

i have 100 variables to execute the command with.
Can I combine it with varlist since I do not want to list all of them in the line?
Also, i still need to loop with forvalue i= 0.01 (1) 0.99 { since I want to calculate all of the percentiles ?
is there a need to generate variables, as I understand gen command does not work with multiple variables.

best Mike

Mike Stu
Guest
Post count: 118

Also Stata says after typing more than one variable after asrol ” varlist required”..

Attaullah Shah
Keymaster
Post count: 69

Mike
I have updated asrol and now multiple statistics / variables can be used in one command. The new version of asdoc can be installed from my site. Copy and paste the following line in Stata and press enter.

net install asrol, from(http://fintechprofessor.com) replace

Please note that the above line has to be copied in full. After installation of the new version, then restart Stata.

Here are few examples:

*Example1: Find mean in a rolling window of -10 and -1 years for two variables: invest and mvalue

webuse grunfeld, clear
asrol invest mvalue , stat(mean) wind(year -10 -1)

*Example2: Find median and mean for a single variable: invest
asrol invest, stat(median mean) window(year -11 -1)
Viewing 5 posts - 1 through 5 (of 5 total)
• You must be logged in to reply to this topic.