-----------------------------------------------------------------------------------------------------------------------------------
      name:  <unnamed>
       log:  /Users/Sergio/Documents/Hacienda/TallerdeVerano/Lunes3Enero/Ejemplo_CASEN/Resultados.txt
  log type:  text
 opened on:   3 Jan 2011, 20:13:36

. 
. drop if nucleo==0                       /*Habilitar en caso de calcular pobreza*/
(24 observations deleted)

. 
. /* Generacion de Variable: Identificacion de hogares*/
. 
. sort region provincia comuna zona segmento idviv hogar 

. egen Fam_ID=group(region provincia comuna zona segmento idviv hogar)

. 
. /* Generacion de Variables: Ejemplo es educacion*/
. 
. /*
> Descripcion de la variable e7t:
> 
>            1 educacin preescolar o educacin parvularia
>            2 preparatoria (sistema antiguo)
>            3 educacin bsica
>            4 educacin diferencial
>            5 humanidades (sistema antiguo)
>            6 educacin media cientfico-humanstica
>            7 tcnica, comercial, industrial o normalista (sistema antiguo
>            8 educacin media tcnica profesional
>            9 centro de formacin tcnica incompleta (sin ttulo)
>           10 centro de formacin tcnica completa ( con ttulo)
>           11 instituto profesional incompleta (sin ttulo)
>           12 instituto profesional completa (con ttulo)
>           13 educacin universitaria incompleta (sin ttulo)
>           14 educacin universitaria completa (con ttulo)
>           15 universitaria de postgrado
>           16 ninguno
> */
. 
. 
. *Generando anios de escolaridad
. gen esc_g=.
(61707 missing values generated)

. replace esc_g=0 if e7t==4
(278 real changes made)

. replace esc_g=0 if e7t==1
(2159 real changes made)

. replace esc_g=e7c if e7t==2
(4532 real changes made)

. replace esc_g=e7c if e7t==3
(20429 real changes made)

. replace esc_g=e7c +8 if e7t==6
(15436 real changes made)

. replace esc_g=e7c +6 if e7t==5
(1710 real changes made)

. replace esc_g=e7c +6 if e7t==7
(250 real changes made)

. replace esc_g=e7c +8 if e7t==8
(4948 real changes made)

. replace esc_g=e7c +12 if e7t==9
(288 real changes made)

. replace esc_g=e7c +12 if e7t==10
(570 real changes made)

. replace esc_g=e7c +12 if e7t==11
(870 real changes made)

. replace esc_g=e7c +12 if e7t==12
(910 real changes made)

. replace esc_g=e7c +12 if e7t==13
(2039 real changes made)

. replace esc_g=e7c +12 if e7t==14
(1597 real changes made)

. replace esc_g=e7c +12 if e7t==15
(151 real changes made)

. replace esc_g=0 if e7t==16
(5540 real changes made)

. 
. corr esc_g esc  /*chequeando nueva variable. Mideplan nos ayuda.*/
(obs=48399)

             |    esc_g      esc
-------------+------------------
       esc_g |   1.0000
         esc |   1.0000   1.0000


. 
. /*********************/
. /*ANALISIS DE POBREZA*/
. /*********************/
. 
. /* Primer paso: INGRESOS*/
. 
. /* Generacion de Variables: Ingreso per capital del hogar*/
. 
. gen i_ingpc=ytothaj/numper

. gen i_autpc=yauthaj/numper

. gen i_subpc=ysubhaj/numper

. gen i_alqpc=yaimhaj/numper

. 
. gen p_aut=(yauthaj/ytothaj)
(157 missing values generated)

. gen p_sub=(ysubhaj/ytothaj)
(157 missing values generated)

. gen p_alq=(yaimhaj/ytothaj)
(157 missing values generated)

. 
. /* Segundo paso: Lineas de pobreza e indigencia*/
. 
. *Linea pobreza
. gen     lin_pob=64134 if z==1
(21913 missing values generated)

. replace lin_pob=43242 if z==2
(21913 real changes made)

. 
. *Linea indigencia
. gen     lin_ind=32067 if z==1
(21913 missing values generated)

. replace lin_ind=24710 if z==2
(21913 real changes made)

. 
. *Variable pobreza
. gen pobre=0

. replace pobre=1 if i_ingpc<lin_pob
(10215 real changes made)

. 
. *Variable indigencia
. gen indigente=0

. replace indigente=1 if i_ingpc<lin_ind
(2642 real changes made)

. 
. *Estadisticas pobreza e indigencia
. tab pobre indigente

           |       indigente
     pobre |         0          1 |     Total
-----------+----------------------+----------
         0 |    51,492          0 |    51,492 
         1 |     7,573      2,642 |    10,215 
-----------+----------------------+----------
     Total |    59,065      2,642 |    61,707 


. tab pobre indigente, col row

+-------------------+
| Key               |
|-------------------|
|     frequency     |
|  row percentage   |
| column percentage |
+-------------------+

           |       indigente
     pobre |         0          1 |     Total
-----------+----------------------+----------
         0 |    51,492          0 |    51,492 
           |    100.00       0.00 |    100.00 
           |     87.18       0.00 |     83.45 
-----------+----------------------+----------
         1 |     7,573      2,642 |    10,215 
           |     74.14      25.86 |    100.00 
           |     12.82     100.00 |     16.55 
-----------+----------------------+----------
     Total |    59,065      2,642 |    61,707 
           |     95.72       4.28 |    100.00 
           |    100.00     100.00 |    100.00 


. tab pobre indigente [w=expr], col row
(frequency weights assumed)

+-------------------+
| Key               |
|-------------------|
|     frequency     |
|  row percentage   |
| column percentage |
+-------------------+

           |       indigente
     pobre |         0          1 |     Total
-----------+----------------------+----------
         0 | 3,613,221          0 | 3,613,221 
           |    100.00       0.00 |    100.00 
           |     88.24       0.00 |     85.11 
-----------+----------------------+----------
         1 |   481,590    150,455 |   632,045 
           |     76.20      23.80 |    100.00 
           |     11.76     100.00 |     14.89 
-----------+----------------------+----------
     Total | 4,094,811    150,455 | 4,245,266 
           |     96.46       3.54 |    100.00 
           |    100.00     100.00 |    100.00 


. 
. tab corte /*Variable ya existente en la base*/

      situacin de |
      indigencia o |
           pobreza |      Freq.     Percent        Cum.
-------------------+-----------------------------------
         indigente |      2,642        4.28        4.28
pobre no indigente |      7,573       12.27       16.55
          no pobre |     51,492       83.45      100.00
-------------------+-----------------------------------
             Total |     61,707      100.00

. tab corte pobre /*Podemos chequear nuestra construccion*/

      situacin de |
      indigencia o |         pobre
           pobreza |         0          1 |     Total
-------------------+----------------------+----------
         indigente |         0      2,642 |     2,642 
pobre no indigente |         0      7,573 |     7,573 
          no pobre |    51,492          0 |    51,492 
-------------------+----------------------+----------
             Total |    51,492     10,215 |    61,707 


. tab corte indigente 

      situacin de |
      indigencia o |       indigente
           pobreza |         0          1 |     Total
-------------------+----------------------+----------
         indigente |         0      2,642 |     2,642 
pobre no indigente |     7,573          0 |     7,573 
          no pobre |    51,492          0 |    51,492 
-------------------+----------------------+----------
             Total |    59,065      2,642 |    61,707 


. 
. /* Tercer paso: Identificacion de hogares con caracteristicas particulares*/
. 
. *Genera dummy: 1(hombre >= 65 anio o mujer >= 60 anio) 0(otro caso)
. gen amayor=((edad>=60 & sexo==2) | (edad>=65 & sexo==1))

. 
. *Indicada si en una familia hay individuos con caracteristicas defininas en amayor
. egen h_amayor=max(amayor), by(Fam_ID)

. 
. *Genera dummy: 1(edad<=5) 0(otro caso)
. gen nino5=(edad<=5)

. *Indicada si en una familia hay individuos con caracteristicas defininas en nino5
. egen h_nino5=sum(nino5), by(Fam_ID)

. 
. /*Cuarto paso: Generacion de Tramos de Edad*/
. 
. gen EDAD=20 if edad<=20
(41348 missing values generated)

. replace EDAD=25 if edad>20 & edad<=25
(4742 real changes made)

. replace EDAD=30 if edad>25 & edad<=30
(3973 real changes made)

. replace EDAD=35 if edad>30 & edad<=35
(3463 real changes made)

. replace EDAD=40 if edad>35 & edad<=40
(4191 real changes made)

. replace EDAD=45 if edad>40 & edad<=45
(4328 real changes made)

. replace EDAD=50 if edad>45 & edad<=50
(4367 real changes made)

. replace EDAD=55 if edad>50 & edad<=65
(9453 real changes made)

. 
. /*Quinto paso: Generacion de condiciones de ocupacion*/
. 
. gen participation=.
(61707 missing values generated)

. replace participation=0 if EDAD>=15 /*Asumimos poblacion ed edad de trabajar >=15*/
(61707 real changes made)

. replace participation=1 if EDAD>=15 & (activ==1 | activ==2)
(25136 real changes made)

. 
. *Indica participacion laboral femenina (empleo o desempleo)
. gen participationF=.
(61707 missing values generated)

. replace participationF=0 if EDAD>=15 & sexo==2
(31337 real changes made)

. replace participationF=1 if EDAD>=15 & (activ==1 | activ==2)  & sexo==2
(9056 real changes made)

. 
. gen empleo=.
(61707 missing values generated)

. replace empleo=0 if EDAD>=15 & (activ==3 | activ==2)
(25807 real changes made)

. replace empleo=1 if EDAD>=15 & (activ==1)
(22592 real changes made)

. 
. *Indica empleo femenino
. gen empleoF=.
(61707 missing values generated)

. replace empleoF=0 if EDAD>=15 & sexo==2 & (activ==3 | activ==2)
(17002 real changes made)

. replace empleoF=1 if EDAD>=15 & (activ==1)  & sexo==2
(7916 real changes made)

. 
. /*Sexto paso: Generacion de percentiles y quintiles*/
. 
. *Genera percentil de ingreso total del hogar
. xtile perc_ing = ytotaj if ytotaj!=. [w=expr], nq(100)
(analytic weights assumed)

. 
. *Genera quintil de ingreso total del hogar
. xtile quint_ing = ytotaj if ytotaj!=. [w=expr], nq(5)
(analytic weights assumed)

. 
. tab quint_ing [w=expr]
(frequency weights assumed)

5 quantiles |
 of ytotaj  |      Freq.     Percent        Cum.
------------+-----------------------------------
          1 |    605,381       23.70       23.70
          2 |    416,299       16.30       40.01
          3 |    510,686       20.00       60.00
          4 |    510,951       20.01       80.01
          5 |    510,523       19.99      100.00
------------+-----------------------------------
      Total |  2,553,840      100.00

. 
. /*RESULTADOS*/
. 
. *Ingreso promedio por quintiles de ingreso
. graph bar ytotaj [w=expr] if perc_ing<26, medtype(line) over(perc_ing) ytitle(Pesos) ///
> title("Ingreso promedio", size(medsmall) color(black) justification(center)) ///
> subtitle("por percentil de ingreso, 2009", size(medsmall) color(black) justification(center)) ///
> note("Fuente:CASEN2009.", span)  
(analytic weights assumed)

. graph save "G1.gph", replace
(file G1.gph saved)

. graph export "G1.eps", replace mag(175) orientation(landscape)  fontface(Garamond)   
(file G1.eps written in EPS format)

. 
. pause
pause:  
-> . q
execution resumes...

. 
. *Distribucion de ingreso
. graph box ytotaj [w=expr] if perc_ing<26, medtype(line) over(perc_ing) ytitle(Pesos) ///
> title("Distribucion de ingreso", size(medsmall) color(black) justification(center)) ///
> subtitle("por percentil de ingreso, 2009", size(medsmall) color(black) justification(center)) ///
> note("Fuente: CASEN2009.", span)
(analytic weights assumed)

. graph save "G2.gph", replace
(file G2.gph saved)

. graph export "G2.eps", replace mag(175) orientation(landscape)  fontface(Garamond)   
(file G2.eps written in EPS format)

. 
. pause
pause:  
-> . q
execution resumes...

. 
. *Edad Promedio" "por decil de ingreso per-capita
. graph bar EDAD [w=expr], over(quint_ing)  ///
> title("Edad Promedio" "por decil de ingreso per-capita") ///
> ytitle(Edad) ///
> note("Fuente: CASEN2009.", span)  
(analytic weights assumed)

. graph save "G3.gph", replace
(file G3.gph saved)

. graph export "G3.eps", replace mag(175) orientation(landscape)  fontface(Garamond)   
(file G3.eps written in EPS format)

. 
. pause
pause:  
-> . q
execution resumes...

. 
. *Anios de escolaridad por quintil de ingreso
. graph bar esc [w=expr], medtype(line) over(quint_ing) ytitle(Escolaridad) ///
> title("Educacion Promedio", size(medsmall) color(black) justification(center)) ///
> subtitle("por percentil de ingreso, 2009", size(medsmall) color(black) justification(center)) ///
> note("Fuente: MIDEPLAN en base a CASEN2009.", span)
(analytic weights assumed)

. graph save "G4.gph", replace
(file G4.gph saved)

. graph export "G4.eps", replace mag(175) orientation(landscape)  fontface(Garamond)
(file G4.eps written in EPS format)

. 
. pause
pause:  
-> . q
execution resumes...

. 
. *Distribucion de anios de escolaridad
. 
. graph box esc [w=expr], medtype(line) over(quint_ing) ytitle(Escolaridad) ///
> title("Distribucion de la Educacion", size(medsmall) color(black) justification(center)) ///
> subtitle("por percentil de ingreso, 2009", size(medsmall) color(black) justification(center)) ///
> note("Fuente: MIDEPLAN en base a CASEN2009.", span)
(analytic weights assumed)

. graph save "G5.gph", replace
(file G5.gph saved)

. graph export "G5.eps", replace mag(175) orientation(landscape)  fontface(Garamond)
(file G5.eps written in EPS format)

. 
. pause
pause:  
-> . q
execution resumes...

. 
. *Empleo sobre fuerza laboral (%)
. 
. graph bar empleo [w=expr] if perc_ing<20, medtype(line) over(perc_ing) ytitle(%) ///
> title("Tasa de Empleo", size(medsmall) color(black) justification(center)) ///
> subtitle("por percentil de ingreso, 2009", size(medsmall) color(black) justification(center)) ///
> note("Fuente: CASEN2009.", span) 
(analytic weights assumed)

. graph save "G6.gph", replace
(file G6.gph saved)

. graph export "G6.eps", replace mag(175) orientation(landscape)  fontface(Garamond)
(file G6.eps written in EPS format)

. 
. pause
pause:  
-> . q
execution resumes...

. 
. *Empleo femenino sobre fuerza laboral (%)
. 
. graph bar empleoF [w=expr] if perc_ing<20, medtype(line) over(perc_ing) ytitle(%)  ///
> title("Tasa de Empleo Femenina", size(medsmall) color(black) justification(center)) ///
> subtitle("por percentil de ingreso, 2009", size(medsmall) color(black) justification(center)) ///
> note("Fuente: CASEN2009.", span)
(analytic weights assumed)

. graph save "G7.gph", replace
(file G7.gph saved)

. graph export "G7.eps", replace mag(175) orientation(landscape)  fontface(Garamond)
(file G7.eps written in EPS format)

. 
. /*Analisis de Regresion*/
. 
. *Variable dependiente
. gen logY=log(ytotaj)
(22753 missing values generated)

. 
. *Variable dicotmica, 1(mujer) 0 (hombre)
. replace sexo=sexo-1
(61707 real changes made)

. 
. *Regresion OLS asumiendo anios de escolaridad como variable continua
. regress logY esc edad sexo 

      Source |       SS       df       MS              Number of obs =   35440
-------------+------------------------------           F(  3, 35436) = 3574.17
       Model |  13781.5471     3  4593.84902           Prob > F      =  0.0000
    Residual |  45545.5881 35436  1.28529146           R-squared     =  0.2323
-------------+------------------------------           Adj R-squared =  0.2322
       Total |  59327.1352 35439  1.67406347           Root MSE      =  1.1337

------------------------------------------------------------------------------
        logY |      Coef.   Std. Err.      t    P>|t|     [95% Conf. Interval]
-------------+----------------------------------------------------------------
         esc |   .1154103   .0015592    74.02   0.000     .1123543    .1184663
        edad |   .0205301   .0003746    54.80   0.000     .0197958    .0212644
        sexo |  -.8373797   .0120798   -69.32   0.000    -.8610564    -.813703
       _cons |   10.26406   .0281255   364.94   0.000     10.20894    10.31919
------------------------------------------------------------------------------

. 
. *Regresion OLS asumiendo anios de escolaridad como variable categorica
. xi: regress logY i.esc edad sexo 
i.esc             _Iesc_0-20          (naturally coded; _Iesc_0 omitted)

      Source |       SS       df       MS              Number of obs =   35440
-------------+------------------------------           F( 22, 35417) =  577.99
       Model |  15673.0211    22  712.410048           Prob > F      =  0.0000
    Residual |  43654.1141 35417  1.23257515           R-squared     =  0.2642
-------------+------------------------------           Adj R-squared =  0.2637
       Total |  59327.1352 35439  1.67406347           Root MSE      =  1.1102

------------------------------------------------------------------------------
        logY |      Coef.   Std. Err.      t    P>|t|     [95% Conf. Interval]
-------------+----------------------------------------------------------------
     _Iesc_1 |   .0756373   .0582543     1.30   0.194    -.0385429    .1898176
     _Iesc_2 |   .0220471   .0431579     0.51   0.609    -.0625437    .1066379
     _Iesc_3 |   .0814705   .0359102     2.27   0.023     .0110853    .1518557
     _Iesc_4 |   .1838592   .0356581     5.16   0.000     .1139683    .2537502
     _Iesc_5 |   .2402646   .0392248     6.13   0.000     .1633827    .3171465
     _Iesc_6 |   .2843796    .030991     9.18   0.000     .2236364    .3451229
     _Iesc_7 |   .3093007   .0426848     7.25   0.000     .2256372    .3929643
     _Iesc_8 |   .5224384   .0297046    17.59   0.000     .4642165    .5806603
     _Iesc_9 |   .2928816   .0382368     7.66   0.000     .2179364    .3678269
    _Iesc_10 |   .4100815   .0344929    11.89   0.000     .3424744    .4776886
    _Iesc_11 |   .2796469   .0398774     7.01   0.000     .2014859    .3578078
    _Iesc_12 |   1.006591   .0280611    35.87   0.000       .95159    1.061591
    _Iesc_13 |   1.152072   .0512585    22.48   0.000     1.051604     1.25254
    _Iesc_14 |   1.426378    .046201    30.87   0.000     1.335823    1.516934
    _Iesc_15 |   1.492782   .0487221    30.64   0.000     1.397285    1.588279
    _Iesc_16 |    1.73118   .0454981    38.05   0.000     1.642002    1.820358
    _Iesc_17 |   2.116161   .0408457    51.81   0.000     2.036102     2.19622
    _Iesc_18 |   2.269813   .0851317    26.66   0.000     2.102953    2.436674
    _Iesc_19 |   2.399457   .1420557    16.89   0.000     2.121024    2.677891
    _Iesc_20 |   2.892517   .2075761    13.93   0.000     2.485662    3.299373
        edad |   .0176553   .0003821    46.20   0.000     .0169063    .0184043
        sexo |  -.8483202   .0118522   -71.57   0.000    -.8715509   -.8250896
       _cons |   10.76993   .0344934   312.23   0.000     10.70232    10.83753
------------------------------------------------------------------------------

. 
. /*El analisis a nivel del hogar*/
. 
. *Promedio variables a nivel de hogar y organizo datos como hogar=fila
. 
. collapse (mean) i_ingpc (mean) numper (mean) expr (mean) participation (mean) empleo (mean) empleoF (mean) EDAD ///
> (sum) amayor (sum) nino5 (mean) pobre (mean) z ///
> (mean) i_autpc (mean) i_subpc (mean) i_alqpc (mean) esc, by(Fam_ID) 

. 
. *Percentiles y quintiles de ingreso per capita, por hogar
. 
. xtile perc_ingpc = i_ingpc if i_ingpc!=. [w=expr], nq(100)
(analytic weights assumed)

. xtile deci_ingpc = i_ingpc if i_ingpc!=. [w=expr], nq(10)
(analytic weights assumed)

. 
. 
. *Distribucion de ingreso per capita del Hogar, por percentil de ingreso per capita del hogar
. 
. graph box i_ingpc [w=expr] if perc_ingpc<26, medtype(line) over(perc_ingpc) ytitle(Pesos) ///
> yline(64134, lcolor(gs12) lstyle(grid)  lpattern(dash)) ///
> text(64134 80 "LP (U)", place(n)) ///
> yline(50000, lcolor(gs8) lstyle(grid) lpattern(dash)) ///
> text(50000 80 "IMF", place(n)) ///
> yline(32067, lcolor(gs2) lstyle(grid) lpattern(dash)) ///
> text(32067 80 "LP (R)", place(n)) ///
> title("Distribucion de ingreso per capita del Hogar", size(medsmall) color(black) justification(center)) ///
> subtitle("por percentil de ingreso per capita del hogar, 2009", size(medsmall) color(black) justification(center)) ///
> note("Fuente: MIDEPLAN en base a CASEN2009.", span)
(analytic weights assumed)

. graph save "G8.gph", replace
(file G8.gph saved)

. graph export "G8.eps", replace mag(175) orientation(landscape)  fontface(Garamond)   
(file G8.eps written in EPS format)

.  
.  pause
pause:  
-> . q
execution resumes...

.  
. *Ingreso per capita promedio del hogar, por percentil de ingreso per capita del hogar 
. 
. graph bar i_ingpc [w=expr] if perc_ingpc<26, medtype(line) over(perc_ingpc) ytitle(Pesos) ///
> yline(64134, lcolor(gs12) lstyle(grid)  lpattern(dash)) ///
> text(64134 4 "LP (U)", place(n)) ///
> yline(50000, lcolor(gs8) lstyle(grid) lpattern(dash)) ///
> text(50000 4 "IMF", place(n)) ///
> yline(32067, lcolor(gs2) lstyle(grid) lpattern(dash)) ///
> text(32067 4 "LP (R)", place(n)) ///
> title("Ingreso per capita promedio del hogar", size(medsmall) color(black) justification(center)) ///
> subtitle("por percentil de ingreso per capita del hogar, 2009", size(medsmall) color(black) justification(center)) ///
> note("Fuente: MIDEPLAN en base a CASEN2009.", span)  
(analytic weights assumed)

. graph save "G9.gph", replace
(file G9.gph saved)

. graph export "G9.eps", replace mag(175) orientation(landscape)  fontface(Garamond)   
(file G9.eps written in EPS format)

. 
. pause
pause:  
-> . q
execution resumes...

. 
. *Descomposicion del Ingreso per capita Promedio del hogar, por percentil de ingreso per capita del hogar
. 
. graph bar (mean) i_autpc i_subpc i_alqpc [w=expr] if perc_ingpc<20, medtype(line) over(perc_ingpc) ytitle(Pesos) ///
> legend(label(1 "Autonomo") label(2 "Subsidios") label(3 "Alquiler imputado")) ///
> asyvars stack legend(caption(Fuente de Ingresos:, position(12))) ///
> yline(64134, lcolor(gs12) lstyle(grid)  lpattern(dash)) ///
> text(64134 4 "LP (U)", place(n)) ///
> yline(50000, lcolor(gs8) lstyle(grid) lpattern(dash)) ///
> text(50000 4 "IMF", place(n)) ///
> yline(32067, lcolor(gs2) lstyle(grid) lpattern(dash)) ///
> text(32067 4 "LP (R)", place(n)) ///
> title("Descomposicion del Ingreso per capita Promedio del hogar",  size(medsmall) color(black) justification(center)) ///
> subtitle("por percentil de ingreso per capita del hogar, 2009", size(medsmall) color(black) justification(center)) ///
> note("Fuente: MIDEPLAN en base a CASEN2009.", span)  
(analytic weights assumed)

. graph save "G10.gph", replace
(file G10.gph saved)

. graph export "G10.eps", replace mag(175) orientation(landscape)  fontface(Garamond)
(file G10.eps written in EPS format)

. 
. *Cierre de archivo resultados.txt
. log close
      name:  <unnamed>
       log:  /Users/Sergio/Documents/Hacienda/TallerdeVerano/Lunes3Enero/Ejemplo_CASEN/Resultados.txt
  log type:  text
 closed on:   3 Jan 2011, 20:14:24
-----------------------------------------------------------------------------------------------------------------------------------
