Hi everyone
I need to construct an average for each variable by different strata for each observation of data but without including the value added by that specific observation in the computed average. Any ideas?
foreach x of varlist col nght dog cancel home atm {
* Count cell size for each weight of each variable
qui egen strat1=count(`x') if strata1~=. , by(strata1)
qui egen strat2=count(`x') if strata2~=. , by(strata2)
qui egen strat3=count(`x') if strata3~=. , by(strata3)
qui egen strat4=count(`x') if strata4~=. , by(strata4)
*******************
* SIMPLE AVERAGES
*******************
qui egen avge2=mean(`x') if strata2~=. , by(strata2) /* sample average */
qui egen avge3=mean(`x') if strata3~=. , by(strata3) /* sample average */
qui egen avge4=mean(`x') if strata4~=. , by(strata4) /* sample average */
qui egen Ia`x'=mean(`x') if strata1~=. , by(strata1) /* population and sample average by strata */
qui replace Ia`x'=avge2 if (strat1<10 | strat1==.) & strat2>=10 & strat2~=.
qui replace Ia`x'=avge3 if (strat2<10 | strat2==.) & strat3>=10 & strat3~=.
qui replace Ia`x'=avge4 if (strat3<10 | strat3==.) & strat4>=10 & strat4~=.
qui replace Ia`x'=. if (strat3<10 & strat4<10) & empresa!=`j'
qui label var Ia`x' "`x' - simple means"
}
Jenniffer Solorzano Mosquera
Labor Markets Division - Inter-American Development Bank
Washington, DC - USA
(202) 623-3659
*
* For searches and help try:
* http://www.stata.com/help.cgi?search
* http://www.stata.com/support/statalist/faq
* http://www.ats.ucla.edu/stat/stata/