Simple coding question. How do I mean correct a set of panel data. The example here is a set of values to TSR by Year and Company, and the companies fall into categories in the variable Category
The coding I was trying is:
gen MeanTSR = 0
forvalues Y = 2005/2018 {
bysort Category: egen meanTSR`Y' = mean(TSR) if Year == Y
replace MeanTSR = meanTSR`Y' if Year == Y
}
gen corrTSR = TSR - MeanTSR
What I find is that I get the same value for all years, as if the if Year == Y was not effective.
There must be a better "Stata" way to do this.
Many thanks
Jamie
Related Posts with Mean correcting a panel data set
xttrans2 - calculating transitional probabilities for multiple years.Hi, I'm a little confused with regards to the xttrans2 command and obtaining transitional probabilit…
Generate new variable without duplicatesHello I have one problem, I need to create a new variable: One extrait of my dataset is the followi…
Variable not found (after others created in the same way)I have the following nested for loops to run the same calculation for different radii, I have bolded…
Excluding*data entriesHi, I have something that is confusing me. I have a dataset and want to merge it with another, but …
merging survey data files - duplicate data problemDear All, I am working on two survey datasets and have encountered the same problem in the small da…
Subscribe to:
Post Comments (Atom)
0 Response to Mean correcting a panel data set
Post a Comment