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
Comparison between Children in the Same HouseholdHello All,
First off, allow me to apologize in advance for any errors I make in the formatting of m…
How to make a graph of mean and standard deviation?Greetings. How can I make this graph of mean and standard deviation in stata? What would the command…
F-Test valuesHello,
I'm performing some quite simple linear regression analyses (with the command reg followed by…
Missing standard errors because of stratum with single sampling unit.How do I fix the problem of missing standard errors because of stratum with single sampling unit whe…
Descriptive statistics after regression: multiple observations per idDear Statalist users,
I am running a conditional risk set model (survival analysis), which entails …
Subscribe to:
Post Comments (Atom)
0 Response to Mean correcting a panel data set
Post a Comment