Hello,
Currently, I am writing my thesis, in which I have to calculate the moving median of the ROE of 48 firm classifications by Fama French (1997). The calculation is as follows:
"To compute a target industry ROE, we group all stocks into the same 48 industry
classifications as Fama and French [1997]. The industry target ROE is a moving median of past ROEs from all firms in the same industry. We use at least five years, and up to ten years, of past data to compute this median."
I already had a look at the last post: https://www.statalist.org/forums/for...for-industries
I used and then modified the code they used in the post because I already selected 5 years. However, I did not manage to get the code right, because I am getting an "if not found" error. Maybe someone knows how to get it right? It would be of great help.
This is the code I now have:
levelsof industry, local(industries)
levelsof Date, local(years)
gen moving_median_roe = .
foreach ind of local industries {
foreach y of local years {
replace moving_median_roe = `r(p50)' if industry == `ind' & Date == `y'
}
}
summ moving_median_roe
This is my data:
Related Posts with Stuck while calculating moving median
How to fit a zero-inflated poisson model in GSEM?Hi friends, BACKGROUND: I have checked all examples showed in SEM/GSEM, but I do not find any examp…
Capturing confidence intervals in newly generated variablesHi, I'm using the following code to determine the 95%CI of a proportion: cii means n_sample n_case…
Controlling for gender in linear regressionHello Statalist! This is my first ever post, and I am newly learning Stata as a somewhat-competent u…
Keeping specific observations within groupsHi everyone, I am having difficulties wrapping my head around the following problem: I have a pane…
Deleting observations from a panel data according to a criteriaHi, I am quite new to STATA (shame on me) and am trying to figure out how to get a desired dataset …
Subscribe to:
Post Comments (Atom)
0 Response to Stuck while calculating moving median
Post a Comment