Explanation: I realize that rangerun itself emulates a loop structure. But I want to perform it for multiple variables. When I run my program, no new variables are created and I want to know if there is a fatal flaw in my thinking. I also tried trace on and found out that the `thing' from inside the foreach loop is not getting passed to the program three_mths.
My code looks almost exactly like this
I realize that you might ask me to unwrap the loop and call rangerun multiple times for each variable high, low, open and close separately. However, the actual dataset I am working with has more than 20 variables. And I need to do the percentile thing for 3, 6, 9, and 12 months - which is why getting this small code correct is so important.
I am also open to other suggestions which might make this easier and/or correct.
Thank you so much, in advance.
My code looks almost exactly like this
Code:
sysuse sp500.dta, clear drop volume change global things high low open close clear programs program three_mths egen `1'_3m = pctile(`1'), p(25) label variable `1'_3m "Top 25 - last 3 months" end set trace on foreach thing in $things { rangerun three_mths, use(`thing') inter(date -90 -1) }
I am also open to other suggestions which might make this easier and/or correct.
Thank you so much, in advance.
Comment