Statalist


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

Re: st: totals by dpto, sex et al.


From   Maarten buis <[email protected]>
To   [email protected]
Subject   Re: st: totals by dpto, sex et al.
Date   Thu, 28 Feb 2008 11:34:13 +0000 (GMT)

Is this what you are looking for?
*------------- begin example ------------------
sysuse auto, clear
bys rep78 foreign : egen long N = count(weight)
list rep78 foreign N in 1/10
*-------------- ende example ------------------
(For more on how to use examples I sent to the Statalist, see
http://home.fsw.vu.nl/m.buis/stata/exampleFAQ.html )

Hope this helps,
Maarten

--- Sebastian Kruk <[email protected]> wrote:

> Dear statlist users,
> 
> I'm computing totals by departament, sex, etc, depending of survey's
> year.
> 
> Next is program:
> 
> *fabrico c85
> *fabricacion de b85
> 
> local i=1991
> while `i' < 1997 {
> 	*Preparacion del archivo con las proyecciones
> 	insheet using "D:\utiles\trimestrestodos.csv", clear
> 	keep if anio==`i'
> 	drop v*
> 	sort agegp e1 trimestre
> 	save D:\utiles\using`i', replace
> 	*Uso archivo del INE
> 	*uso archivo del IEcon
> 	*use "d:\personas\p`i'.dta", clear
> 	*use "D:\utiles\p95.dta", clear
> 	*drop  aniosed-lp02
> 	*ren nivel pe141
> 	*ren finalizo pe15
> 	*keep pe* pobpcoac pf* pg*  ph* pt1 pt2 pt3
> 	use d:\personas\p`i'.dta, clear
> 	ren pe3 e2
> 	ren pe1c dpto
> 	ren pe2 e1
> 	ren pe1b semana
> 	ren pe1a anio
> 	replace anio=`i'
> 	ren pe1g loc
> 	*como hay cuatro casos en los cuales el valor de la variable sexo es
> 0 se van a eliminar. Adem�s en los cuatro la edad es cero por lo cual
> no tienen ingresos.n dos casos y por 2 en los otros dos.
> 	drop if e1==0
> 	*drop if e2==.
> 	sort dpto loc
> 	merge dpto loc using "D:\utiles\b85.dta", uniqusing nokeep
> _merge(_merge1)
> 	replace borrar=1 if dpto==1
> 	drop if borrar == 0
> 	*union con la proyeccion y obtencion de la poblacion expandida
> 	gen trimestre=1
> 	replace trimestre=2 if inrange(semana, 13,24)
> 	replace trimestre=3 if inrange(semana, 25,36)
> 	replace trimestre=4 if semana >36
> 	egen agegp=cut(e2),
> at(0,5,10,15,20,25,30,35,40,45,50,55,60,65,70,75,80,100)
> 	label define agegp 0 "0-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+"
> 	sort e1 trimestre agegp	
> 	bysort e1 trimestre agegp: gen N_e1_trimestre_agegp=_N
> 	joinby e1 trimestre agegp using "d:\utiles\using`i'.dta",
> unmatched(master)
> 	gen expansor = proyeccion / N_e1_trimestre_agegp
> 	save "d:\personas\final`i'.dta", replace
> 	forvalues x = 1(1)5 {
> 		egen y`x' = rowtotal(pg`x'?p) if pobpcoac<21
> 		gen e_y`x' = 3*expansor*(y`x')
> 		forvalues t=1(1)4 {
> 			egen e_y`x'`t'=total(e_y`x')if trimestre==`t'
> 		}
> 	}
> 	foreach x of numlist 1 2 {
> 		gen b`x' = pg`x'4p+pg`x'5p if pobpcoac<21
> 		gen e_b`x' = 3*expansor*(b`x')
> 		forvalues t=1(1)4 {
> 			egen e_b`x'`t'=total(e_b`x')if trimestre==`t'
> 		}
> 	}
> 	forvalues x = 1(1)5 {
> 		forvalues t=1(1)4 {
> 			egen e_y_`x'`t'=max(e_y`x'`t')
> 		}
> 	}
> 	forvalues x = 1 (1) 2 {
> 		forvalues t=1(1)4 {
> 			egen e_b_`x'`t'=max(e_b`x'`t')	
> 		}
> 	}
> 	forvalues t=1(1)4 {
> 		gen
> masa_tri_`t'=e_y_1`t'+e_y_2`t'+e_y_3`t'+0.73*e_y_4`t'+0.4*e_y_5`t'
> 		gen masa_tri_`t'_sbs=masa_tri_`t'-(e_b_1`t'+e_b_2`t')
> 	}	
> 	keep masa*
> 	keep in l
> 	gen anio=`i'
> 	save d:\utiles\masa`i', replace
> 	local i = `i' + 1
> }
> 
> Thanx,
> 
> Sebasti�n Kruk.
> 
> *
> *   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/
> 


-----------------------------------------
Maarten L. Buis
Department of Social Research Methodology
Vrije Universiteit Amsterdam
Boelelaan 1081
1081 HV Amsterdam
The Netherlands

visiting address:
Buitenveldertselaan 3 (Metropolitan), room Z434

+31 20 5986715

http://home.fsw.vu.nl/m.buis/
-----------------------------------------


      ___________________________________________________________
Yahoo! Answers - Got a question? Someone out there knows the answer. Try it
now.
http://uk.answers.yahoo.com/
*
*   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