-------------
       log:  C:\Mis documentos\Cursos impartidos\Tecnicas de Medicion\Otros\evaluacion_ycontinuo.smcl
  log type:  smcl
 opened on:  10 Nov 2003, 00:00:55

. use t9194_4

. 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)

. /*La variable resultado es el numero ideal de hijos*/
. tab idealnum, miss

      Ideal |
  number of |
   children |      Freq.     Percent        Cum.
------------+-----------------------------------
          0 |          1        0.01        0.01
          1 |         19        0.22        0.23
          2 |        203        2.33        2.56
          3 |        457        5.24        7.80
          4 |      1,561       17.91       25.71
          5 |      1,254       14.38       40.09
          6 |      1,560       17.89       57.98
          7 |        520        5.96       63.95
          8 |        570        6.54       70.49
          9 |        143        1.64       72.13
         10 |        977       11.21       83.33
         11 |         25        0.29       83.62
         12 |         96        1.10       84.72
         13 |         11        0.13       84.85
         14 |          5        0.06       84.90
         15 |         44        0.50       85.41
         17 |          1        0.01       85.42
         18 |          1        0.01       85.43
         19 |          1        0.01       85.44
         20 |         28        0.32       85.77
         30 |          4        0.05       85.81
          . |      1,237       14.19      100.00
------------+-----------------------------------
      Total |      8,718      100.00

. /*La variable de programa es un mensaje de radio que habla sobre metodos de Planificacion Familiar*/
. /*¿Cuantas personas estan siendo afectadas por el programa?*/
. tab fpmess, miss

   Heard FP |
 message in |
last 6 mths |      Freq.     Percent        Cum.
------------+-----------------------------------
          0 |      5,209       59.75       59.75
          1 |      3,509       40.25      100.00
------------+-----------------------------------
      Total |      8,718      100.00

.
. /*SUPONIENDO UN DISENO EXPERIMENTAL*/
. /*La prueba adecuada es una prueba "t" de diferencias*/
. ttest idealnum, by(fpmess)

Two-sample t test with equal variances

---------+--------------------------------------------------------------------
   Group |     Obs        Mean    Std. Err.   Std. Dev.   [95% Conf. Interval]
---------+--------------------------------------------------------------------
       0 |    4289    6.423176    .0424551    2.780401    6.339942    6.506409
       1 |    3192     5.76817     .041722      2.3572    5.686366    5.849975
---------+--------------------------------------------------------------------
combined |    7481    6.143697    .0303854    2.628121    6.084133    6.203261
---------+--------------------------------------------------------------------
    diff |            .6550051    .0609705                .5354859    .7745244
---------+--------------------------------------------------------------------
Degrees of freedom: 7479

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

     Ha: diff < 0               Ha: diff != 0              Ha: diff > 0
       t =  10.7430                t =  10.7430              t =  10.7430
   P < t =   1.0000          P > |t| =   0.0000          P > t =   0.0000

. *El resultado de la prueba me indica que existe una diferencia de 0.655 entre el promedio del numero ideal de hijos de las mujeres que no escucharon el mensaje en relación con aquellas que si lo escucharon*
. *Utilizo la cola superior porque espero que el grupo que si escucho el mensaje tenga un promedio menor, lo que implica una diferencia mayor que cero*
.
. /*Ahora usemos los resultados de una regresion simple*/
. regress idealnum fpmess

      Source |       SS       df       MS              Number of obs =    7481
-------------+------------------------------           F(  1,  7479) =  115.41
       Model |  785.142867     1  785.142867           Prob > F      =  0.0000
    Residual |  50879.3825  7479  6.80296597           R-squared     =  0.0152
-------------+------------------------------           Adj R-squared =  0.0151
       Total |  51664.5253  7480   6.9070221           Root MSE      =  2.6082

-------------+----------------------------------------------------------------
    idealnum |      Coef.   Std. Err.      t    P>|t|     [95% Conf. Interval]
-------------+----------------------------------------------------------------
      fpmess |  -.6550051   .0609705   -10.74   0.000    -.7745244   -.5354859
       _cons |   6.423176   .0398264   161.28   0.000     6.345105    6.501247
-------------+----------------------------------------------------------------

. *Observo el mismo resultado obtenido con ttest* En promedio el grupo que si escuchó el mensaje tiene 0.655 hijos menos que aquellas que no*
.
. /*SUPONIENDO UN DISENO OBSERVACIONAL DONDE LA MUESTRA FUE SELECCIONADA POR MUESTREO SIMPLE*/
. /*Sabemos que este diseño no es un experimento.  Es recomendable buscar algunas variables de control que expliquen mejor el número ideal de hijos*/
.
. /*Otros factores pueden ser NSE, edad, educación, región de residencia.  Para poder incorporarlas en el modelo necesito construir algunas categorías y luego unas dummy*/
. tab1 sumasset agef gradef rural

-> tabulation of sumasset

  Number of |
  assets in |
  household |      Freq.     Percent        Cum.
------------+-----------------------------------
          0 |      4,370       50.43       50.43
          1 |      2,894       33.40       83.83
          2 |      1,216       14.03       97.86
          3 |        118        1.36       99.23
          4 |         45        0.52       99.75
          5 |         15        0.17       99.92
          6 |          7        0.08      100.00
------------+-----------------------------------
      Total |      8,665      100.00

-> tabulation of agef

 Age of the |
      woman |      Freq.     Percent        Cum.
------------+-----------------------------------
         15 |        361        4.14        4.14
         16 |        467        5.36        9.50
         17 |        412        4.73       14.22
         18 |        437        5.01       19.24
         19 |        417        4.78       24.02
         20 |        433        4.97       28.99
         21 |        314        3.60       32.59
         22 |        367        4.21       36.80
         23 |        341        3.91       40.71
         24 |        295        3.38       44.09
         25 |        331        3.80       47.89
         26 |        287        3.29       51.18
         27 |        296        3.40       54.58
         28 |        301        3.45       58.03
         29 |        251        2.88       60.91
         30 |        359        4.12       65.03
         31 |        200        2.29       67.32
         32 |        209        2.40       69.72
         33 |        149        1.71       71.43
         34 |        151        1.73       73.16
         35 |        264        3.03       76.19
         36 |        186        2.13       78.32
         37 |        154        1.77       80.09
         38 |        211        2.42       82.51
         39 |        147        1.69       84.19
         40 |        217        2.49       86.68
         41 |        137        1.57       88.25
         42 |        139        1.59       89.85
         43 |        132        1.51       91.36
         44 |         84        0.96       92.33
         45 |        187        2.14       94.47
         46 |        135        1.55       96.02
         47 |        101        1.16       97.18
         48 |        146        1.67       98.85
         49 |        100        1.15      100.00
------------+-----------------------------------
      Total |      8,718      100.00

-> tabulation of gradef

    Highest |
     formal |
  schooling |      Freq.     Percent        Cum.
------------+-----------------------------------
          0 |      3,056       35.05       35.05
          1 |         59        0.68       35.73
          2 |        204        2.34       38.07
          3 |        240        2.75       40.82
          4 |        684        7.85       48.67
          5 |        282        3.23       51.90
          6 |        352        4.04       55.94
          7 |      3,524       40.42       96.36
          8 |         35        0.40       96.77
          9 |         26        0.30       97.06
         10 |         55        0.63       97.69
         11 |         35        0.40       98.10
         12 |        143        1.64       99.74
         13 |          1        0.01       99.75
         14 |          7        0.08       99.83
         15 |         15        0.17      100.00
------------+-----------------------------------
      Total |      8,718      100.00

-> tabulation of rural

 1 if rural |
 area, 0 if |
      urban |      Freq.     Percent        Cum.
------------+-----------------------------------
          0 |      1,630       18.70       18.70
          1 |      7,088       81.30      100.00
------------+-----------------------------------
      Total |      8,718      100.00

.
. /* Es recomendable convertir la suma de artefactos en categorica y luego en dummy* (cumplir con el supuesto de linealidad)*/
. gen artefact=sumasset
(53 missing values generated)

. recode artefact 0=1 1 2=2 3 4 5 6=3
(artefact: 7331 changes made)

. tab artefact, gen(artefact_)

   artefact |      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

. /*Verificar la construccion de las dummies*/
. 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

.
. /*Prueba de asociacion*/
. tab idealnum artefact, chi

     Ideal |
 number of |             artefact
  children |         1          2          3 |     Total
-----------+---------------------------------+----------
         0 |         1          0          0 |         1
         1 |         9         10          0 |        19
         2 |        91         94         17 |       202
         3 |       200        239         14 |       453
         4 |       653        824         74 |     1,551
         5 |       613        607         26 |     1,246
         6 |       778        758         23 |     1,559
         7 |       256        254          7 |       517
         8 |       315        249          3 |       567
         9 |        81         58          1 |       140
        10 |       536        422          9 |       967
        11 |        14         11          0 |        25
        12 |        45         50          0 |        95
        13 |         6          5          0 |        11
        14 |         4          1          0 |         5
        15 |        22         22          0 |        44
        17 |         0          1          0 |         1
        18 |         1          0          0 |         1
        19 |         1          0          0 |         1
        20 |        14         14          0 |        28
        30 |         3          1          0 |         4
-----------+---------------------------------+----------
     Total |     3,643      3,620        174 |     7,437

         Pearson chi2(40) = 161.5259   Pr = 0.000

.
. /*Prueba de correlacion*/
. corr idealnum sumasset agef gradef
(obs=7437)

             | idealnum sumasset     agef   gradef
-------------+------------------------------------
    idealnum |   1.0000
    sumasset |  -0.1014   1.0000
        agef |   0.2668  -0.0737   1.0000
      gradef |  -0.3372   0.2113  -0.4388   1.0000


.
. /*Regresion*/
. regress idealnum fpmess artefact_1 artefact_2 agef gradef rural

      Source |       SS       df       MS              Number of obs =    7437
-------------+------------------------------           F(  6,  7430) =  218.33
       Model |  7693.82815     6  1282.30469           Prob > F      =  0.0000
    Residual |  43637.5114  7430  5.87315092           R-squared     =  0.1499
-------------+------------------------------           Adj R-squared =  0.1492
       Total |  51331.3395  7436  6.90308493           Root MSE      =  2.4235

-------------+----------------------------------------------------------------
    idealnum |      Coef.   Std. Err.      t    P>|t|     [95% Conf. Interval]
-------------+----------------------------------------------------------------
      fpmess |  -.3747907   .0591581    -6.34   0.000    -.4907573   -.2588242
  artefact_1 |   .3556304    .194256     1.83   0.067    -.0251663    .7364272
  artefact_2 |   .3938705    .191725     2.05   0.040     .0180352    .7697057
        agef |   .0472871   .0034183    13.83   0.000     .0405862     .053988
      gradef |  -.1761416   .0097932   -17.99   0.000    -.1953391   -.1569442
       rural |   .7003986   .0741449     9.45   0.000     .5550536    .8457436
       _cons |    4.84371   .2338827    20.71   0.000     4.385234    5.302187
-------------+----------------------------------------------------------------

.
. /*Decidir si excluir alguna variable, presencia de efectos no lineales*/
. test artefact_1 artefact_2

 ( 1)  artefact_1 = 0
 ( 2)  artefact_2 = 0

       F(  2,  7430) =    2.21
            Prob > F =    0.1103

. test artefact_1=artefact_2

 ( 1)  artefact_1 - artefact_2 = 0

       F(  1,  7430) =    0.43
            Prob > F =    0.5119

.
. /*Prueba consiste en verificar si ambas son iguales a cero y por tanto no estan aportando explicacion al modelo*/
. *El coeficiente asociado a la clase baja no es diferentes al coeficiente asociado a la clase media*
. *Implica: se puede hacer en una sola categoria*
.
. /*Tambien los efectos no lineales se pueden probar en educación.  SUGERENCIA: Divida los años de escolaridad de manera tal que quede primaria incompleta, completa y secundaria o mas*/
. *tab gradef
. *gen edu6=(gradef>=1 & gradef<=6)
. *gen edu7=(gradef==7)
. *gen edu8=(gredef>=8)
.
. /*MODELO CON LA PRESENCIA DE INTERACCIONES*/
. *Variable de programa con variable confusora*
. gen fprural=fpmess*rural

. tab fprural

    fprural |      Freq.     Percent        Cum.
------------+-----------------------------------
          0 |      6,188       70.98       70.98
          1 |      2,530       29.02      100.00
------------+-----------------------------------
      Total |      8,718      100.00

. gen fpage=fpmess*agef

. tab fpage

      fpage |      Freq.     Percent        Cum.
------------+-----------------------------------
          0 |      5,209       59.75       59.75
         15 |         61        0.70       60.45
         16 |        102        1.17       61.62
         17 |        117        1.34       62.96
         18 |        139        1.59       64.56
         19 |        175        2.01       66.56
         20 |        169        1.94       68.50
         21 |        154        1.77       70.27
         22 |        175        2.01       72.28
         23 |        170        1.95       74.23
         24 |        157        1.80       76.03
         25 |        164        1.88       77.91
         26 |        147        1.69       79.59
         27 |        157        1.80       81.39
         28 |        131        1.50       82.90
         29 |        126        1.45       84.34
         30 |        169        1.94       86.28
         31 |        102        1.17       87.45
         32 |         82        0.94       88.39
         33 |         70        0.80       89.19
         34 |         64        0.73       89.93
         35 |        109        1.25       91.18
         36 |         86        0.99       92.17
         37 |         67        0.77       92.93
         38 |         72        0.83       93.76
         39 |         56        0.64       94.40
         40 |         95        1.09       95.49
         41 |         61        0.70       96.19
         42 |         47        0.54       96.73
         43 |         45        0.52       97.25
         44 |         32        0.37       97.61
         45 |         56        0.64       98.26
         46 |         47        0.54       98.80
         47 |         32        0.37       99.16
         48 |         48        0.55       99.71
         49 |         25        0.29      100.00
------------+-----------------------------------
      Total |      8,718      100.00

.
. /*Probar si la variable de programa tiene un efecto diferenciado por zona o por edad*/
. regress idealnum fpmess fprural fpage artefact_1 artefact_2 agef gradef rural

      Source |       SS       df       MS              Number of obs =    7437
-------------+------------------------------           F(  8,  7428) =  163.85
       Model |  7699.73032     8   962.46629           Prob > F      =  0.0000
    Residual |  43631.6092  7428  5.87393769           R-squared     =  0.1500
-------------+------------------------------           Adj R-squared =  0.1491
       Total |  51331.3395  7436  6.90308493           Root MSE      =  2.4236

-------------+----------------------------------------------------------------
    idealnum |      Coef.   Std. Err.      t    P>|t|     [95% Conf. Interval]
-------------+----------------------------------------------------------------
      fpmess |  -.1934203   .2134822    -0.91   0.365    -.6119058    .2250653
     fprural |  -.1243066   .1443169    -0.86   0.389    -.4072085    .1585954
       fpage |  -.0029712   .0063434    -0.47   0.640    -.0154061    .0094638
  artefact_1 |   .3528251   .1943728     1.82   0.070    -.0282006    .7338508
  artefact_2 |    .391247   .1918023     2.04   0.041     .0152601    .7672339
        agef |   .0483799   .0041032    11.79   0.000     .0403365    .0564234
      gradef |  -.1760671   .0097965   -17.97   0.000     -.195271   -.1568633
       rural |    .772314   .1107454     6.97   0.000     .5552217    .9894062
       _cons |   4.754255   .2507009    18.96   0.000      4.26281      5.2457
-------------+----------------------------------------------------------------

.
. /*Se pueden excluir las interacciones?.  Es el modelo adecuado sin ellas*/
. test fprural=fpage

 ( 1)  fprural - fpage = 0

       F(  1,  7428) =    0.70
            Prob > F =    0.4020

.
. /*Estimacion de predichos y prueba de supuestos para los residuos*/
. predict pidealnum
(option xb assumed; fitted values)
(53 missing values generated)

. predict res, rstu
(1281 missing values generated)

. sum idealnum pidealnum res

    Variable |       Obs        Mean    Std. Dev.       Min        Max
-------------+--------------------------------------------------------
    idealnum |      7481    6.143697    2.628121          0         30
   pidealnum |      8665     6.22721     1.03669   3.134728   8.288433
         res |      7437    .0000988    1.000633  -2.613512   9.635835

.
. /*Pruebas de normalidad*/
. *1-Grafico
. rvfplot

. *2-Verificar problemas con los ajustes de los datos
. list cluster line hhid agef idealnum pidealnum res if (abs(res)>3 & res!=.)

      +---------------------------------------------------------------+
      | cluster   line   hhid   agef   idealnum   pideal~m        res |
      +---------------------------------------------------------------+
 112. |     253      2     89     24         20    5.51369   5.995399 |
 438. |     111      2    109     42         20   7.177459   5.307344 |
 905. |      64      3      6     38         15   6.677615   3.439775 |
1061. |       1      3     10     38         15   6.677615   3.439775 |
1162. |     111      2     81     29         20    6.54852   5.567717 |
      +---------------------------------------------------------------+
1405. |     107      1     73     30         20   6.314344   5.663408 |
1679. |      77      2     36     40         20   6.673749   5.512726 |
1981. |     324      8     89     48         17   8.240053   3.620242 |
1991. |     306     10      1     20         15   5.275794   4.018136 |
2069. |     212      2    136     18         13   5.517763    3.09005 |
      +---------------------------------------------------------------+
2095. |     206      2    204     42         20   7.468835   5.183235 |
2356. |     308      7     38     18         15   5.556185   3.901663 |
2378. |     292      2     70     26         15   7.137272   3.247251 |
2462. |     250      2    223     25         20   7.088892   5.338708 |
2649. |     196      2     29     35         15   7.150974   3.242172 |
      +---------------------------------------------------------------+
2697. |     224      2    214     38         20   7.717832   5.077886 |
2872. |     229      5     33     16         14   6.653473   3.034629 |
2922. |      72      2    124     44         15   7.598074   3.058473 |
3047. |      90      2    134     34         15   7.562734   3.071517 |
3119. |      69      2     38     29         20   7.282412    5.25817 |
      +---------------------------------------------------------------+
3249. |      85      2     81     44         20   8.008111   4.958361 |
3665. |     317      5     24     18         15   5.517763   3.917546 |
3691. |      11      3     35     15         14   5.724757   3.418194 |
3843. |     260      2     32     35         20   7.572692   5.137843 |
3879. |     278      3     41     15         15   6.643515   3.452784 |
      +---------------------------------------------------------------+
3913. |      72      1    123     43         15   7.514244   3.092893 |
3941. |     136      5     49     37         20   6.965183    5.39017 |
4174. |     273      6     55     19         15   5.604565   3.881573 |
4238. |      95      2    139     35         15   7.611114   3.051549 |
4330. |     314      5    142     35         15   6.270638   3.606204 |
      +---------------------------------------------------------------+
4405. |     294      4     25     28         15   7.272454   3.191513 |
4453. |     268      5      4     16         20   5.459425   6.016062 |
4669. |     305      2    112     19         20   5.604565   5.955388 |
4723. |     153      3     37     21         20   6.933794   5.403913 |
4754. |      24      2     10     15         14    5.04875   3.698977 |
      +---------------------------------------------------------------+
4811. |     147      2    131     46         30   8.104871   9.089046 |
5033. |     129      1    402     48         20   8.240053   4.863503 |
5108. |     215      2    214     33         15   7.514354   3.091493 |
5116. |     306      2     20     36         15   6.955225    3.32275 |
5163. |     305     14    104     19         15   5.604565   3.881573 |
      +---------------------------------------------------------------+
5488. |     310      2    169     29         20   7.282412    5.25817 |
5515. |     197      3    108     33         15   7.123797    3.25259 |
5529. |      95      3    135     47         20   8.191673   4.883331 |
5698. |     324      2     82     32         20   6.195082   5.710171 |
5723. |     291      1    167     32         20   7.289907   5.255242 |
      +---------------------------------------------------------------+
6054. |     312      5     70     17         15   5.683872   3.848809 |
6095. |     312      5     66     27         15   7.224074   3.211547 |
6187. |      88      5    102     47         30   7.734301   9.249148 |
6269. |      93      3    139     31         15   5.736869   3.827036 |
6325. |     130      2     11     45         15   7.643483   3.039887 |
      +---------------------------------------------------------------+
6339. |     292      3     50     16         15    5.59707   3.884793 |
6482. |       9      2     24     32         20   6.547216   5.563293 |
6531. |     213      2     53     42         20   7.507257    5.16741 |
6923. |     229     11     29     15         19   6.605093   5.126057 |
6973. |     316      1    106     43         20   7.998153   4.962775 |
      +---------------------------------------------------------------+
7002. |     214      2     56     45         15   7.352222   3.159476 |
7076. |     314     14    155     17         15   5.507805   3.921766 |
7371. |       5      2    160     40         15   6.673749   3.440067 |
7396. |     241      9     67     26         15   7.175694    3.23159 |
7419. |     146      2    221     31         30   7.379172   9.390593 |
      +---------------------------------------------------------------+
7435. |     149      3    130     17         20   5.469383   6.011764 |
7573. |     275      3     47     34         15   7.348245   3.159862 |
7636. |     242      4     76     25         15   7.088892   3.267308 |
7763. |      95      2    135     41         20   7.901393   5.002578 |
7844. |      87      3     15     42         20   7.507257    5.16741 |
      +---------------------------------------------------------------+
7853. |      95      1    119     36         15   7.659493    3.03159 |
7926. |     327      2      2     35         30    6.79884   9.635835 |
7978. |      77      2     28     42         15    7.38315   3.146115 |
8029. |      91      2      3     36         20   7.621072   5.117842 |
8169. |      70      2    170     23         18    5.93573   4.987005 |
      +---------------------------------------------------------------+
8411. |      76      2     45     22         15    5.32819   3.996315 |
8637. |      92     13     56     45         20   8.056491   4.938489 |
8646. |     248      3     22     19         13   5.191964   3.225313 |
      +---------------------------------------------------------------+

. *3- Test
. sktest res

                   Skewness/Kurtosis tests for Normality
                                                 ------- joint ------
    Variable |  Pr(Skewness)   Pr(Kurtosis)  adj chi2(2)    Prob>chi2
-------------+-------------------------------------------------------
         res |      0.000         0.000               .            .

.
. /*Escenarios para estimar el contrafactico*/
. gen fpmesscopy=fpmess

. *1-  Sin programa
. replace fpmess=0
(3509 real changes made)

. predict pidealnum_0
(option xb assumed; fitted values)
(53 missing values generated)

. *2- Cobertura 100%
. replace fpmess=1
(8718 real changes made)

. predict pidealnum_100
(option xb assumed; fitted values)
(53 missing values generated)

.
. sum idealnum pidealnum*

    Variable |       Obs        Mean    Std. Dev.       Min        Max
-------------+--------------------------------------------------------
    idealnum |      7481    6.143697    2.628121          0         30
   pidealnum |      8665     6.22721     1.03669   3.134728   8.288433
 pidealnum_0 |      8665    6.305248    1.009457   3.328148   8.288433
pidealnu~100 |      8665    6.111828    1.009457   3.134728   8.095013

.
. /*Vuelvo fpmess a su estado natural*/
. replace fpmess=fpmesscopy
(5209 real changes made)

.
. /*Cierro la base que nunca salve*/
. clear

.
. /*Cierro el log*/
. log close
       log:  C:\Mis documentos\Cursos impartidos\Tecnicas de Medicion\Otros\evaluacion_ycontinuo.smcl
  log type:  smcl
 closed on:  10 Nov 2003, 00:01:37
-------------