Home › Forums › ASROL : Rolling Window and byGroup Descriptive Statistics › 12 month rolling percentiles
Tagged: asrol, rolling percentiles, Stata, window

AuthorPosts

Mike StuGuestAugust 26, 2020 at 6:46 pmPost 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 firmmonth 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(P`d') } } forvalue i=1 (1) 99 { replace P_`x'=0 if`x'<P1 replace P_`x'=`i' if `x'>P`i'  `x'==P`i' & `x'<P`i'+1 replace P_`x'=100 if`x'>P99 replace P_`x'=. if`x'==. } forvalue i=1 (1) 99 { drop P`i' } }
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 This topic was modified 3 years, 5 months ago by Attaullah Shah.
 This topic was modified 3 years, 5 months ago by Attaullah Shah.
 This topic was modified 3 years, 5 months ago by Attaullah Shah.
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 StuGuestAugust 26, 2020 at 7:44 pmPost count: 118Thank you for your fast reply!
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.Thanks in advance!
best Mike
Mike StuGuestAugust 26, 2020 at 8:16 pmPost count: 118Also Stata says after typing more than one variable after asrol ” varlist required”..
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)
 This reply was modified 3 years, 5 months ago by Attaullah Shah.

AuthorPosts
 You must be logged in to reply to this topic.