I hope you are all doing well. I am afraid I have a question regarding the calculation of the mean inside a centile range. I would like to calculate the mean of the variable change1m_ inside the centile range c(24 69) for every year since 2000. My code is the following:
HTML Code:
putexcel set Trimmed_PCE.xlsx, sheet(data) replace putexcel A1 = "Year" putexcel B1 = "Month" putexcel C1 = "Trimmed mean" local row = 2 forvalues y = 2000(1)2021 { forvalues m = 1(1)12{ preserve keep if year==`y' & month==`m' gsort -change1m_ centile change1m_, c(24 69) asgen wtm_`y'`m' = change1m_ if inrange( change1m_, `r(c_1)', `r(c_2)'), w(weight_) summarize wtm_`y'`m' putexcel A`row' = `y' putexcel B`row' = `m' putexcel C`row' = `r(mean)' local ++row restore } }
0 Response to Trimmed Mean
Post a Comment