-------------
       log:  C:\Collado\Talleres\Evaluacion03\Taller Evaluacion 2003\Bases Datos\Tanzania_9194\evaluacion_ydicotomico.smcl
  log type:  smcl
 opened on:  12 Nov 2003, 22:05:57

. use t9194_4

. /*Filtro la base de datos*/
. tab wave91

     wave91 |      Freq.     Percent        Cum.
------------+-----------------------------------
          0 |      4,225       32.64       32.64
          1 |      8,718       67.36      100.00
------------+-----------------------------------
      Total |     12,943      100.00

. keep if wave91==1
(4225 observations deleted)

. /*Analisis Crudo*/
. /*Comparacion de proporciones: quienes escucharon vs quienes no escucharon el mesaje de radio*/
. *Cual es la hipotesis que quiero probar?
. prtest curuse, by (fpmess)

Two-sample test of proportion                      0: Number of obs =     5209
                                                   1: Number of obs =     3509

-------------+----------------------------------------------------------------
    Variable |       Mean   Std. Err.      z    P>|z|     [95% Conf. Interval]
-------------+----------------------------------------------------------------
           0 |   .0424266   .0027927                      .0369529    .0479002
           1 |    .122827   .0055411                      .1119666    .1336874
-------------+----------------------------------------------------------------
        diff |  -.0804004   .0062051                     -.0925622   -.0682387
             |  under Ho:   .0057448   -14.00   0.000
-------------+----------------------------------------------------------------

               Ho: proportion(0) - proportion(1) = diff = 0

       Ha: diff < 0            Ha: diff != 0             Ha: diff > 0
        z = -13.995              z = -13.995              z = -13.995
    P < z =  0.0000        P > |z| =  0.0000          P > z =  1.0000

. /*Modelo con los OR*/
. logistic curuse fpmess

Logistic regression                               Number of obs   =       8718
                                                  LR chi2(1)      =     191.83
                                                  Prob > chi2     =     0.0000
Log likelihood = -2221.7726                       Pseudo R2       =     0.0414

-------------+----------------------------------------------------------------
      curuse | Odds Ratio   Std. Err.      z    P>|z|     [95% Conf. Interval]
-------------+----------------------------------------------------------------
      fpmess |   3.160406   .2713219    13.40   0.000     2.670957    3.739545
-------------+----------------------------------------------------------------

. /*Preparo las variables para el modelo de regresion*/
. /*Formar alternativa de codificar.  Solo aplica en Stata8*/
. recode sumasset (0=1) (1 2=2) (3 4 5 6=3), gen (artefact)
(7331 differences between sumasset and artefact)

. tab artefact, gen(artefact_)

  RECODE of |
   sumasset |
 (Number of |
  assets in |
 household) |      Freq.     Percent        Cum.
------------+-----------------------------------
          1 |      4,370       50.43       50.43
          2 |      4,110       47.43       97.86
          3 |        185        2.14      100.00
------------+-----------------------------------
      Total |      8,665      100.00

. tab1 artefact_*

-> tabulation of artefact_1

 artefact== |
     1.0000 |      Freq.     Percent        Cum.
------------+-----------------------------------
          0 |      4,295       49.57       49.57
          1 |      4,370       50.43      100.00
------------+-----------------------------------
      Total |      8,665      100.00

-> tabulation of artefact_2

 artefact== |
     2.0000 |      Freq.     Percent        Cum.
------------+-----------------------------------
          0 |      4,555       52.57       52.57
          1 |      4,110       47.43      100.00
------------+-----------------------------------
      Total |      8,665      100.00

-> tabulation of artefact_3

 artefact== |
     3.0000 |      Freq.     Percent        Cum.
------------+-----------------------------------
          0 |      8,480       97.86       97.86
          1 |        185        2.14      100.00
------------+-----------------------------------
      Total |      8,665      100.00

. logistic curuse fpmess artefact_2 artefact_3 agef gradef rural

Logistic regression                               Number of obs   =       8665
                                                  LR chi2(6)      =     443.60
                                                  Prob > chi2     =     0.0000
Log likelihood = -2086.7334                       Pseudo R2       =     0.0961

-------------+----------------------------------------------------------------
      curuse | Odds Ratio   Std. Err.      z    P>|z|     [95% Conf. Interval]
-------------+----------------------------------------------------------------
      fpmess |   2.197992   .1983854     8.73   0.000     1.841614    2.623333
  artefact_2 |   1.215695   .1101346     2.16   0.031     1.017914    1.451906
  artefact_3 |   1.220461    .274085     0.89   0.375     .7858967     1.89532
        agef |   1.039021    .005377     7.40   0.000     1.028536    1.049614
      gradef |   1.214855   .0187842    12.59   0.000     1.178591    1.252235
       rural |   .6589628   .0632819    -4.34   0.000     .5459059    .7954338
-------------+----------------------------------------------------------------

. /*Si queremos ver los coeficientes*/
. logit

Logit estimates                                   Number of obs   =       8665
                                                  LR chi2(6)      =     443.60
                                                  Prob > chi2     =     0.0000
Log likelihood = -2086.7334                       Pseudo R2       =     0.0961

-------------+----------------------------------------------------------------
      curuse |      Coef.   Std. Err.      z    P>|z|     [95% Conf. Interval]
-------------+----------------------------------------------------------------
      fpmess |   .7875441   .0902576     8.73   0.000     .6106425    .9644458
  artefact_2 |   .1953163   .0905939     2.16   0.031     .0177555    .3728771
  artefact_3 |   .1992289    .224575     0.89   0.375      -.24093    .6393877
        agef |    .038279   .0051751     7.40   0.000      .028136    .0484221
      gradef |   .1946244   .0154621    12.59   0.000     .1643193    .2249296
       rural |  -.4170882   .0960326    -4.34   0.000    -.6053087   -.2288677
       _cons |  -4.761703   .2285768   -20.83   0.000    -5.209705   -4.313701
-------------+----------------------------------------------------------------

. /*Pruebas de Linealidad*/
. test artefact_2 artefact_3

 ( 1)  artefact_2 = 0
 ( 2)  artefact_3 = 0

           chi2(  2) =    4.72
         Prob > chi2 =    0.0946

. * Cual es la conclusion estadistica de la prueba? y cual la teorica?.
. * Tiene sentido sacar las variables que miden el NSE o se busca como mejorar la medicion?
. /*Modelo con interacciones*/
. gen fprural=fpmess*rural

. gen fpage=fpmess*agef

. logistic curuse fpmess fprural fpage artefact_2 artefact_3 agef gradef rural

Logistic regression                               Number of obs   =       8665
                                                  LR chi2(8)      =     452.49
                                                  Prob > chi2     =     0.0000
Log likelihood = -2082.2894                       Pseudo R2       =     0.0980

-------------+----------------------------------------------------------------
      curuse | Odds Ratio   Std. Err.      z    P>|z|     [95% Conf. Interval]
-------------+----------------------------------------------------------------
      fpmess |   4.225601   1.295373     4.70   0.000     2.317126    7.705971
     fprural |   1.172063   .2336715     0.80   0.426     .7929555    1.732419
       fpage |   .9731769    .009064    -2.92   0.004     .9555729    .9911052
  artefact_2 |   1.226806   .1112743     2.25   0.024     1.026999    1.465487
  artefact_3 |   1.242824   .2788038     0.97   0.333     .8006799    1.929125
        agef |   1.054665   .0076124     7.37   0.000      1.03985    1.069691
      gradef |   1.216648   .0188747    12.64   0.000     1.180211     1.25421
       rural |   .5924356   .1004689    -3.09   0.002     .4249024    .8260249
-------------+----------------------------------------------------------------

. logit

Logit estimates                                   Number of obs   =       8665
                                                  LR chi2(8)      =     452.49
                                                  Prob > chi2     =     0.0000
Log likelihood = -2082.2894                       Pseudo R2       =     0.0980

-------------+----------------------------------------------------------------
      curuse |      Coef.   Std. Err.      z    P>|z|     [95% Conf. Interval]
-------------+----------------------------------------------------------------
      fpmess |   1.441162   .3065536     4.70   0.000     .8403276    2.041995
     fprural |   .1587654   .1993677     0.80   0.426    -.2319882     .549519
       fpage |  -.0271894   .0093138    -2.92   0.004    -.0454442   -.0089346
  artefact_2 |   .2044141   .0907024     2.25   0.024     .0266406    .3821876
  artefact_3 |   .2173863   .2243309     0.97   0.333    -.2222941    .6570667
        agef |   .0532235   .0072178     7.37   0.000     .0390768    .0673702
      gradef |   .1960996   .0155137    12.64   0.000     .1656934    .2265059
       rural |  -.5235131   .1695861    -3.09   0.002    -.8558958   -.1911304
       _cons |  -5.119723   .2943662   -17.39   0.000     -5.69667   -4.542776
-------------+----------------------------------------------------------------

. *Que dicen las interacciones?
. *Cual modelo es preferible con o sin interacciones?
. predict pcuruse
(option p assumed; Pr(curuse))
(53 missing values generated)

. /*Prueba de normalidad de los residuos*/
. predict resi, de
(53 missing values generated)

. sum fpmess curuse pcuruse res

    Variable |       Obs        Mean    Std. Dev.       Min        Max
-------------+--------------------------------------------------------
      fpmess |      8718    .4025006    .4904299          0          1
      curuse |      8718    .0747878    .2630637          0          1
     pcuruse |      8665    .0750144    .0667096   .0078071    .624505
        resi |      8665   -.2580904    1.111494  -2.768942   3.392558

. /*Son similares en promedio, hay que ver que pasa con los grupos especificos*/
. list cluster line hhid agef gradef curuse pcuruse res if (abs(res)>3 & res!=.)

      +----------------------------------------------------------------------+
      | cluster   line   hhid   agef   gradef   curuse    pcuruse       resi |
      +----------------------------------------------------------------------+
 279. |      64      2     34     33        0        1    .056283   3.392558 |
 799. |     160      2     85     33        3        1   .0586876   3.367805 |
1132. |     160      2     91     33        3        1   .0586876   3.367805 |
1310. |       1      2     19     33        0        1    .056283   3.392558 |
1868. |       4      8    186     17        0        0   .0086764   3.243467 |
      +----------------------------------------------------------------------+
1975. |     303      3     82     17        0        0   .0086764   3.243467 |
2222. |     209      2    183     36        7        1   .1501556   3.372907 |
2451. |     277      5     60     17        0        0   .0086764   3.243467 |
2816. |     303      5     97     17        0        0   .0086764   3.243467 |
3277. |     293      4     10     17        0        0   .0086764   3.243467 |
      +----------------------------------------------------------------------+
3805. |      75      4     50     17        0        0   .0086764   3.243467 |
4101. |     273      5     50     17        0        1   .0086764   3.243467 |
4297. |     130     12    129     17        0        1   .0086764   3.243467 |
4675. |     151      4    149     17        0        0   .0086764   3.243467 |
4762. |     259      1     43     36        7        1   .1501556   3.372907 |
      +----------------------------------------------------------------------+
4855. |      45      2    300     36        7        1   .1501556   3.372907 |
5019. |      41      2    181     38        6        1   .0798679   3.179548 |
5076. |       4      6    192     17        0        0   .0086764   3.243467 |
5085. |     136      4     69     17        0        0   .0086764   3.243467 |
5311. |     241     14     69     17        0        0   .0086764   3.243467 |
      +----------------------------------------------------------------------+
5360. |     308      2     45     17        0        0   .0086764   3.243467 |
5428. |      87      4     22     17        0        1   .0086764   3.243467 |
5607. |     291      3    160     17        0        0   .0086764   3.243467 |
5913. |       6      2    139     17        0        0   .0086764   3.243467 |
6045. |     312      7     56     17        0        0   .0086764   3.243467 |
      +----------------------------------------------------------------------+
6457. |     135      3    220     17        0        0   .0086764   3.243467 |
6501. |     243      3     70     17        0        0   .0086764   3.243467 |
6575. |      84      2    130     23        5        1   .0945237   3.071745 |
6916. |     241      3     70     17        0        0   .0086764   3.243467 |
6957. |     309      2     13     17        0        0   .0086764   3.243467 |
      +----------------------------------------------------------------------+
7394. |     152     13     68     17        0        0   .0086764   3.243467 |
7554. |      90      4    118     17        0        0   .0086764   3.243467 |
7871. |     281      2     84     23        5        1   .0945237   3.071745 |
8002. |     130      1     17     38        6        1   .0798679   3.179548 |
8008. |      14      4    162     17        0        0   .0086764   3.243467 |
      +----------------------------------------------------------------------+
8093. |     270      4     78     17        0        0   .0086764   3.243467 |
      +----------------------------------------------------------------------+

. /*Bondad de ajuste*/
. lfit


Logistic model for curuse, goodness-of-fit test


       number of observations =      8665
 number of covariate patterns =      1521
           Pearson chi2(1512) =      1675.98
                  Prob > chi2 =         0.0019

. lfit, group(10)


Logistic model for curuse, goodness-of-fit test


  (Table collapsed on quantiles of estimated probabilities)

       number of observations =      8665
             number of groups =        10
      Hosmer-Lemeshow chi2(8) =        37.01
                  Prob > chi2 =         0.0000

. *Ho:  Valores observados= Valores predichos
. *Que dice la bondad de ajuste?
. /*Prediciones para el calculo del impacto*/
. *Hacer copia de la variable de programa
. gen fpmesscopia=fpmess

. *Estimo el contrafactico
. replace fpmess=0
(3509 real changes made)

. predict pcuruse0
(option p assumed; Pr(curuse))
(53 missing values generated)

. *Estimo cobertura 100
. replace fpmess=1
(8718 real changes made)

. predict pcuruse100
(option p assumed; Pr(curuse))
(53 missing values generated)

. *Comparo las predicciones con la realidad para obtener el impacto
. sum curuse pcuruse*

    Variable |       Obs        Mean    Std. Dev.       Min        Max
-------------+--------------------------------------------------------
      curuse |      8718    .0747878    .2630637          0          1
     pcuruse |      8665    .0750144    .0667096   .0078071    .624505
    pcuruse0 |      8665    .0390905    .0302841   .0060963   .4451523
  pcuruse100 |      8665    .1395817    .0836138   .0252638   .7722192

. *Cual es el impacto del programa?
. clear

. log close
       log:  C:\Collado\Talleres\Evaluacion03\Taller Evaluacion 2003\Bases Datos\Tanzania_9194\evaluacion_ydicotomico.smcl
  log type:  smcl
 closed on:  12 Nov 2003, 22:05:59
-------------