Statalist


[Date Prev][Date Next][Thread Prev][Thread Next][Date index][Thread index]

st: Re: RE: weight and easier way


From   "Michael Blasnik" <[email protected]>
To   <[email protected]>
Subject   st: Re: RE: weight and easier way
Date   Thu, 12 Jul 2007 07:59:40 -0400

...
I'm not sure exactly what you are doing, but it doesn't seem like you need a loop at all, or even many commands.

1) Create the agegp variable and save the master dataset.

2) Create a dataset with the "proyection" constants by department and gender. It should have three variables: dpto, el, and proyection. Sort it by dpto el before saving it as proyection.dta

Then:

use masterdata
bysort dpto agegp el: gen N_dpto_agegp_el=_N
bysort dpto el: gen N_dpto_el=_N
merge dpto el using proyection, nokeep
gen corrector=N_dpto/(proyection*N_dpto_agegp_el)


Michael Blasnik

----- Original Message ----- From: "Sebastian Kruk" <[email protected]>
To: <[email protected]>
Sent: Thursday, July 12, 2007 7:39 AM
Subject: st: RE: weight and easier way



Hi dear statalist users,

I have been in vacation but I work anyway.

Do you remember my problem?

I have a households survey and population proyections.

All the weights are wrong.

Some of my varriables are:

<snip>
Weights in microsurvey are wrong, It must be corrected by new one
using population proyections.

I do the next but I have problems using a loop.

*Make a categorical variable for group of age:

egen agegp=cut(e2), at
(0,1,5,10,15,20,25,30,35,40,45,50,55,60,65,70,75,80,85,90,95,100)

*Put labels

label define agegp 0 "0" 1 "1-4" 5 "5-9" 10 "10-14" 15 "15-19" 20
"20-25" 25 "25-29" 30 "30-34" 35 "35-39" 40 "40-44" 45 "45-49" 50
"50-54" 55 "55-59" 60 "60-64" 65 "65-69" 70 "70-74" 75 "75-79" 80
"80-84" 85 "85-89" 90 "90-94" 95 "95+"

*Compute number of men by group of age and departamento (means state in English)

egen n_h_0=total(agegp==0 & e1==1), by (dpto)
egen n_h_1=total(agegp==1 & e1==1), by (dpto)
<snip>
egen n_h_95=total(agegp==95 & e1==1), by (dpto)

*Computo total men by departemanto
egen h_dpto=rowtotal(n_h_*)

*Repit for women
egen n_m_0= total(agegp==0 & e1=!1), by (dpto)
…………………………………………………..
egen n_m_95=total(agegp==95 & e1=!1), by (dpto)
egen m_dpto=rowtotal(n_m_*)

*Make a constan equals men's proyection by departamento

gen h_1_p=643547
gen h_2_p=
…………………..
gen h_19_p=

*Repet for women
gen m_1_p=
gen m_2_p=
…………………..
gen m_19_p=

*Compute annual men expansor by departemanto
gen corrector=h_dpto/(h_1_p*n_h_0) if  e1==1 & agegp==0
replace corrector=h_dpto/(h_1_p*n_h_1) if  e1==1 & agegp==1
<snip>
replace corrector=h_dpto/(h_1_p*n_h_95) if  e1==1 & agegp==95

*Repet for women
replace corrector=h_dpto/(h_1_p*n_h_0) if  e1==1

Bye,

Sebastian.
*
*   For searches and help try:
*   http://www.stata.com/support/faqs/res/findit.html
*   http://www.stata.com/support/statalist/faq
*   http://www.ats.ucla.edu/stat/stata/



© Copyright 1996–2024 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   What's new   |   Site index