Statalist


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

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


From   "Sebastian Kruk" <residuo.solow@gmail.com>
To   statalist@hsphsun2.harvard.edu
Subject   Re: st: RE: totals by dpto, sex et al.
Date   Thu, 28 Feb 2008 08:55:05 -0300

I would like to some totals by sex, departament, etc and then store
this values in a variable to posteriori use.

Sebastian.

2008/2/28 Martin Weiss <martin.weiss@uni-tuebingen.de>:
> Unless I am missing something, there is no question here to answer to. If
> there was one, it would be helpful to have it framed in terms of a dataset
> shipped with Stata so that the list can relate to your problem...
>
> Martin Weiss
> _________________________________________________________________
>
> Diplom-Kaufmann Martin Weiss
> Mohlstrasse 36
> Room 415
> 72074 Tuebingen
> Germany
>
> Fon: 0049-7071-2978184
>
> Home: http://www.wiwi.uni-tuebingen.de/cms/index.php?id=1130
>
> Publications: http://www.wiwi.uni-tuebingen.de/cms/index.php?id=1131
>
> SSRN: http://papers.ssrn.com/sol3/cf_dev/AbsByAuth.cfm?per_id=669945
>
> -----Original Message-----
> From: owner-statalist@hsphsun2.harvard.edu
> [mailto:owner-statalist@hsphsun2.harvard.edu] On Behalf Of Sebastian Kruk
> Sent: Thursday, February 28, 2008 12:13 PM
> To: statalist@hsphsun2.harvard.edu
> Subject: st: totals by dpto, sex et al.
>
> 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/
>
>
> *
> *   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/
>

*
*   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–2014 StataCorp LP   |   Terms of use   |   Privacy   |   Contact us   |   What's new   |   Site index