Hello Statalist Community,
I am currently working on a project where I need to perform univariate tests for several variables over a specific time period. The variables in question are dacc_noturnover, dacc_cfoturnover, dacc_ceoturnover, and dacc_ceocfoturnover. My goal is to analyze these variables for the years 2017, 2018, and 2019.
Specifically, I am looking to calculate both the median and mean for each of these variables for each year. I would like to present this data in a table format, where each variable is listed with the mean and median values for 2017, 2018, and 2019 side by side.
Could anyone guide me on how to:
Any assistance or guidance on how to approach this in Stata would be greatly appreciated.
Thank you in advance for your help!
Best regards
Johanna
My code:
I am currently working on a project where I need to perform univariate tests for several variables over a specific time period. The variables in question are dacc_noturnover, dacc_cfoturnover, dacc_ceoturnover, and dacc_ceocfoturnover. My goal is to analyze these variables for the years 2017, 2018, and 2019.
Specifically, I am looking to calculate both the median and mean for each of these variables for each year. I would like to present this data in a table format, where each variable is listed with the mean and median values for 2017, 2018, and 2019 side by side.
Could anyone guide me on how to:
- Perform univariate tests for these variables in Stata, focusing on calculating the median and mean for each year.
- Create a table in Stata that aligns with the following structure:
Variable | 2017 | 2018 | 2019 | |||
Mean | Median | Mean | Median | Mean | Median | |
dacc_noturnover | [X] | [x] | [x] | [x] | [x] | [x] |
Thank you in advance for your help!
Best regards
Johanna
My code:
Code:
scalar minObs= 1 drop if fyear !=2016 & fyear!= 2017 & fyear != 2018 & fyear != 2019 tostring sic, replace drop sic_2 gen sic_2 = substr(sic,1,2) destring sic_2, replace summ sic_2 scalar a= 0 /*r(min)*/ scalar b= 99 /*r(max)*/ di sic_2 summ fyear scalar c= 2017 /*r(min)*/ scalar d= 2019 /*r(max) */ summ dummy_T_CEOCFO scalar e= 0 scalar f= 1 summ dummy_T_CEO scalar g = 0 scalar h = 1 summ dummy_T_CFO scalar i = 0 scalar k = 1 summ No_Turnover scalar m = 1 scalar n = 1 drop uhat gen uhat=. xtset gvkey fyear /*drop obs gen obs= [_n] summ obs scalar e= r(min) scalar f= r(max)*/ /*Erstellen der notwendigen Variablen*/ drop tac_scaled gen tac_scaled= (ib-oancf)/L.at drop inverse_lagassets gen inverse_lagassets= 1/L.at drop lagrevrec gen lagrevrec= (d.revt - d.rect)/L.at drop ppeg_scaled gen ppeg_scaled = cond(ppegt == ., ppent/L.at, ppegt/L.at) forvalues j = 1/`=_N' { if fyear[`j']>= c & fyear[`j']<=d & sic_2[`j'] >= a & sic_2[`j'] <= b { capture noisily { reg tac_scaled inverse_lagassets lagrevrec ppeg_scaled if sic_2 == sic_2[`j'] & fyear == fyear[`j'] & _n != `j' & No_Turnover == 1, nocons di e(N) if e(N) >= minObs { predict uhat_2 in `j', resid replace uhat = uhat_2 in `j' drop uhat_2 } } foreach fyear in 2017 2018 2019 { drop dacc_turnover gen dacc_turnover = . replace dacc_turnover = uhat if dummy_T_CFO == 1 | dummy_T_CEO == 1 | dummy_T_CEOCFO == 1 } } } drop dacc_noturnover gen dacc_noturnover = . replace dacc_noturnover = uhat if No_Turnover == 1 drop dacc_cfoturnover gen dacc_cfoturnover = . replace dacc_cfoturnover = uhat if dummy_T_CFO == 1 & dummy_T_CEO == 0 & dummy_T_CEOCFO == 0 drop dacc_ceoturnover gen dacc_ceoturnover = . replace dacc_ceoturnover = uhat if dummy_T_CEO == 1 & dummy_T_CFO == 0 & dummy_T_CEOCFO == 0 drop dacc_ceocfoturnover gen dacc_ceocfoturnover = . replace dacc_ceocfoturnover = uhat if dummy_T_CEOCFO == 1 tabstat dacc_turnover , statistics(median, mean, min, max) tabstat dacc_noturnover, statistics(median, mean, min, max) tabstat dacc_ceoturnover , statistics(median, mean, min, max) tabstat dacc_cfoturnover , statistics(median, mean, min, max) tabstat dacc_ceocfoturnover , statistics(median, mean, min, max)