Showing posts with label STATA code. Show all posts
Showing posts with label STATA code. Show all posts

Friday, April 15, 2016

Graduate Level Health Economics Econometric Solutions to Woolridge Computer Problems C6.4 C6.10 9.3 9.4 C9.1 C9.8

. use "E:\data\gpa2-1.dta"

. regress sat hsize hsizesq

      Source |       SS       df       MS              Number of obs =    4137
-------------+------------------------------           F(  2,  4134) =   15.93
       Model |  614822.097     2  307411.048           Prob > F      =  0.0000
    Residual |  79759024.2  4134  19293.4263           R-squared     =  0.0076
-------------+------------------------------           Adj R-squared =  0.0072
       Total |  80373846.3  4136  19432.7481           Root MSE      =   138.9

------------------------------------------------------------------------------
         sat |      Coef.   Std. Err.      t    P>|t|     [95% Conf. Interval]
-------------+----------------------------------------------------------------
       hsize |   19.81446   3.990666     4.97   0.000     11.99061    27.63831
     hsizesq |  -2.130606    .549004    -3.88   0.000    -3.206949   -1.054263
       _cons |   997.9805   6.203448   160.88   0.000     985.8184    1010.143
------------------------------------------------------------------------------

. * Yes the quadratic term is statistically significant

. *The optimal high school size

. gen logsat = ln(sat)

. regress logsat hsize hsizesq

      Source |       SS       df       MS              Number of obs =    4137
-------------+------------------------------           F(  2,  4134) =   16.19
       Model |  .614405203     2  .307202602           Prob > F      =  0.0000
    Residual |  78.4287724  4134  .018971643           R-squared     =  0.0078
-------------+------------------------------           Adj R-squared =  0.0073
       Total |  79.0431776  4136   .01911102           Root MSE      =  .13774

------------------------------------------------------------------------------
      logsat |      Coef.   Std. Err.      t    P>|t|     [95% Conf. Interval]
-------------+----------------------------------------------------------------
       hsize |   .0196029   .0039572     4.95   0.000     .0118445    .0273612
     hsizesq |  -.0020872   .0005444    -3.83   0.000    -.0031546   -.0010199
       _cons |   6.896029   .0061515  1121.03   0.000     6.883969    6.908089
------------------------------------------------------------------------------

. *using the logsat as the DV the optimal high school size is 469

. clear

. use "E:\data\bwght2-1.dta"

. regress lbwght lbwght npvis npvissq

      Source |       SS       df       MS              Number of obs =    1764
-------------+------------------------------           F(  3,  1760) =       .
       Model |  74.2054098     3  24.7351366           Prob > F      =       .
    Residual |           0  1760           0           R-squared     =  1.0000
-------------+------------------------------           Adj R-squared =  1.0000
       Total |  74.2054098  1763   .04209042           Root MSE      =       0

------------------------------------------------------------------------------
      lbwght |      Coef.   Std. Err.      t    P>|t|     [95% Conf. Interval]
-------------+----------------------------------------------------------------
      lbwght |          1          .        .       .            .           .
       npvis |  -7.94e-19          .        .       .            .           .
     npvissq |  -2.30e-20          .        .       .            .           .
       _cons |  -1.78e-15          .        .       .            .           .
------------------------------------------------------------------------------

. regress lbwght npvis npvissq

      Source |       SS       df       MS              Number of obs =    1764
-------------+------------------------------           F(  2,  1761) =   19.12
       Model |   1.5771321     2  .788566048           Prob > F      =  0.0000
    Residual |  72.6282777  1761  .041242634           R-squared     =  0.0213
-------------+------------------------------           Adj R-squared =  0.0201
       Total |  74.2054098  1763   .04209042           Root MSE      =  .20308

------------------------------------------------------------------------------
      lbwght |      Coef.   Std. Err.      t    P>|t|     [95% Conf. Interval]
-------------+----------------------------------------------------------------
       npvis |   .0189167   .0036806     5.14   0.000     .0116979    .0261355
     npvissq |  -.0004288     .00012    -3.57   0.000    -.0006641   -.0001934
       _cons |   7.957883   .0273125   291.36   0.000     7.904314    8.011451
------------------------------------------------------------------------------

. *Yes the quadratic term is statistically significant

. tab nvpis
variable nvpis not found
r(111);

. tab npvis

      total |
  number of |
   prenatal |
     visits |      Freq.     Percent        Cum.
------------+-----------------------------------
          0 |          5        0.28        0.28
          1 |          2        0.11        0.40
          2 |          5        0.28        0.68
          3 |         12        0.68        1.36
          4 |          6        0.34        1.70
          5 |         27        1.53        3.23
          6 |         59        3.34        6.58
          7 |         58        3.29        9.86
          8 |        117        6.63       16.50
          9 |         96        5.44       21.94
         10 |        199       11.28       33.22
         11 |        115        6.52       39.74
         12 |        618       35.03       74.77
         13 |         72        4.08       78.85
         14 |         97        5.50       84.35
         15 |        143        8.11       92.46
         16 |         41        2.32       94.78
         17 |         12        0.68       95.46
         18 |         15        0.85       96.32
         19 |          4        0.23       96.54
         20 |         35        1.98       98.53
         21 |          5        0.28       98.81
         22 |          2        0.11       98.92
         23 |          1        0.06       98.98
         24 |          2        0.11       99.09
         25 |          3        0.17       99.26
         26 |          1        0.06       99.32
         30 |          7        0.40       99.72
         33 |          1        0.06       99.77
         35 |          1        0.06       99.83
         36 |          1        0.06       99.89
         40 |          2        0.11      100.00
------------+-----------------------------------
      Total |      1,764      100.00

. gen visits = .
(1832 missing values generated)

. replace visits = 1 if npvis >= 22
(89 real changes made)

. tab visits

     visits |      Freq.     Percent        Cum.
------------+-----------------------------------
          1 |         89      100.00      100.00
------------+-----------------------------------
      Total |         89      100.00

. tab npvis if npvis >21

      total |
  number of |
   prenatal |
     visits |      Freq.     Percent        Cum.
------------+-----------------------------------
         22 |          2        9.52        9.52
         23 |          1        4.76       14.29
         24 |          2        9.52       23.81
         25 |          3       14.29       38.10
         26 |          1        4.76       42.86
         30 |          7       33.33       76.19
         33 |          1        4.76       80.95
         35 |          1        4.76       85.71
         36 |          1        4.76       90.48
         40 |          2        9.52      100.00
------------+-----------------------------------
      Total |         21      100.00

. tab npvis visits

     total |
 number of |
  prenatal |   visits
    visits |         1 |     Total
-----------+-----------+----------
        22 |         2 |         2
        23 |         1 |         1
        24 |         2 |         2
        25 |         3 |         3
        26 |         1 |         1
        30 |         7 |         7
        33 |         1 |         1
        35 |         1 |         1
        36 |         1 |         1
        40 |         2 |         2
-----------+-----------+----------
     Total |        21 |        21


. *Yes it does make sense in that if there are thatmany visits it could be a problemat
> ic pregnancy with the likelihood of lower birth outcomes

. regress lbwght npvis npvissq mage magesq

      Source |       SS       df       MS              Number of obs =    1764
-------------+------------------------------           F(  4,  1759) =   11.56
       Model |  1.90136387     4  .475340968           Prob > F      =  0.0000
    Residual |  72.3040459  1759    .0411052           R-squared     =  0.0256
-------------+------------------------------           Adj R-squared =  0.0234
       Total |  74.2054098  1763   .04209042           Root MSE      =  .20274

------------------------------------------------------------------------------
      lbwght |      Coef.   Std. Err.      t    P>|t|     [95% Conf. Interval]
-------------+----------------------------------------------------------------
       npvis |   .0180374   .0037086     4.86   0.000     .0107636    .0253112
     npvissq |  -.0004079   .0001204    -3.39   0.001    -.0006441   -.0001717
        mage |    .025392   .0092542     2.74   0.006     .0072417    .0435423
      magesq |  -.0004119   .0001548    -2.66   0.008    -.0007154   -.0001083
       _cons |   7.583713   .1370568    55.33   0.000     7.314901    7.852524
------------------------------------------------------------------------------

. *The optimal age is 31

. gen age = .
(1832 missing values generated)

. replace age = 1 if mage > 31
(605 real changes made)

. replace age = 0 if mage <= 31
(1227 real changes made)

. tab age

        age |      Freq.     Percent        Cum.
------------+-----------------------------------
          0 |      1,227       66.98       66.98
          1 |        605       33.02      100.00
------------+-----------------------------------
      Total |      1,832      100.00

. regress bwght npvis npvissq mage magesq

      Source |       SS       df       MS              Number of obs =    1764
-------------+------------------------------           F(  4,  1759) =    8.59
       Model |  11376019.1     4  2844004.78           Prob > F      =  0.0000
    Residual |   582383777  1759  331087.992           R-squared     =  0.0192
-------------+------------------------------           Adj R-squared =  0.0169
       Total |   593759796  1763  336789.448           Root MSE      =   575.4

------------------------------------------------------------------------------
       bwght |      Coef.   Std. Err.      t    P>|t|     [95% Conf. Interval]
-------------+----------------------------------------------------------------
       npvis |   37.47386   10.52531     3.56   0.000     16.83042     58.1173
     npvissq |  -.7862864   .3417884    -2.30   0.022     -1.45664   -.1159322
        mage |   81.60554   26.26395     3.11   0.002     30.09369    133.1174
      magesq |  -1.327179   .4392829    -3.02   0.003     -2.18875   -.4656073
       _cons |   1860.381    388.977     4.78   0.000     1097.475    2623.286
------------------------------------------------------------------------------
9.3
       Let math10 denote the percentage of students at a Michigan high school receiving a passing score on a standardized math test (see also Ex 4.2).  We are interested in estimating the effect of per student spending on math performance.  A simple model is

i)       You need to be “poor” to be in the federally funded student lunch program.
ii)      Because lnchprg is negatively correlated with log(expend).  It is significant.
iii)    Yes
iv)      Math10 would decrease by 3.24% if lunch program increase by 10%.
v)       It’s a good predictor variable because R-squared is increasing.

9.4

(i)
Tvhours= tvhours*+e0
(ii)
It’s not likely to hold in the example, because if the tvhours=0 then they would be reported as zero
So the error depends on the actual tvhours

C9.1
(i)

. use "C:\Users\sphl\Desktop\CEOSAL1-1.DTA"

. generate rosneg = 0

. replace rosneg = 1 if (ros<1)
(23 real changes made)

. regress lsalary lsales roe rosneg

      Source |       SS       df       MS              Number of obs =     209
-------------+------------------------------           F(  3,   205) =   28.81
       Model |  19.7902019     3  6.59673397           Prob > F      =  0.0000
    Residual |  46.9319613   205  .228936397           R-squared     =  0.2966
-------------+------------------------------           Adj R-squared =  0.2863
       Total |  66.7221632   208  .320779631           Root MSE      =  .47847

------------------------------------------------------------------------------
     lsalary |      Coef.   Std. Err.      t    P>|t|     [95% Conf. Interval]
-------------+----------------------------------------------------------------
      lsales |   .2883868   .0336172     8.58   0.000      .222107    .3546665
         roe |   .0166571   .0039681     4.20   0.000     .0088336    .0244806
      rosneg |   -.225675    .109338    -2.06   0.040    -.4412462   -.0101038
       _cons |   4.297602   .2932526    14.65   0.000     3.719425     4.87578
------------------------------------------------------------------------------

. ovtest

Ramsey RESET test using powers of the fitted values of lsalary
       Ho:  model has no omitted variables
                 F(3, 202) =      1.07
                  Prob > F =      0.3614

** We accept the null-hypothesis

C9.8
   1.  New update available; type -update all-

. use "C:\Users\sphl\Desktop\twoyear.dta"

. codebook stotal

--------------------------------------------------------------------------------------
stotal                                                   total standardized test score
--------------------------------------------------------------------------------------

                  type:  numeric (float)

                 range:  [-3.3247969,2.2353656]       units:  1.000e-09
         unique values:  227                      missing .:  0/6763

                  mean:   .047483
              std. dev:   .853544

           percentiles:        10%       25%       50%       75%       90%
                          -1.10531  -.327343         0   .610791   1.13706

. reg stotal jc

      Source |       SS       df       MS              Number of obs =    6763
-------------+------------------------------           F(  1,  6761) =    1.03
       Model |  .752020193     1  .752020193           Prob > F      =  0.3097
    Residual |   4925.6191  6761  .728534108           R-squared     =  0.0002
-------------+------------------------------           Adj R-squared =  0.0000
       Total |  4926.37112  6762  .728537581           Root MSE      =  .85354

------------------------------------------------------------------------------
      stotal |      Coef.   Std. Err.      t    P>|t|     [95% Conf. Interval]
-------------+----------------------------------------------------------------
          jc |    .013658   .0134431     1.02   0.310    -.0126946    .0400107
       _cons |   .0428543   .0113348     3.78   0.000     .0206344    .0650741
------------------------------------------------------------------------------

. reg stotal univ

      Source |       SS       df       MS              Number of obs =    6763
-------------+------------------------------           F(  1,  6761) = 1574.72
       Model |  930.653211     1  930.653211           Prob > F      =  0.0000
    Residual |  3995.71791  6761  .590995106           R-squared     =  0.1889
-------------+------------------------------           Adj R-squared =  0.1888
       Total |  4926.37112  6762  .728537581           Root MSE      =  .76876

------------------------------------------------------------------------------
      stotal |      Coef.   Std. Err.      t    P>|t|     [95% Conf. Interval]
-------------+----------------------------------------------------------------
        univ |   .1615085     .00407    39.68   0.000       .15353    .1694869
       _cons |  -.2636267   .0122004   -21.61   0.000    -.2875434     -.23971
------------------------------------------------------------------------------

. reg lwage jc univ exper stotal

      Source |       SS       df       MS              Number of obs =    6763
-------------+------------------------------           F(  4,  6758) =  500.23
       Model |  367.406832     4  91.8517079           Prob > F      =  0.0000
    Residual |  1240.88926  6758  .183617825           R-squared     =  0.2284
-------------+------------------------------           Adj R-squared =  0.2280
       Total |  1608.29609  6762  .237843255           Root MSE      =  .42851

------------------------------------------------------------------------------
       lwage |      Coef.   Std. Err.      t    P>|t|     [95% Conf. Interval]
-------------+----------------------------------------------------------------
          jc |   .0630514   .0068214     9.24   0.000     .0496792    .0764235
        univ |   .0686405   .0025651    26.76   0.000     .0636121     .073669
       exper |   .0048773   .0001571    31.04   0.000     .0045692    .0051854
      stotal |   .0493766   .0068096     7.25   0.000     .0360277    .0627255
       _cons |   1.495271   .0212176    70.47   0.000     1.453678    1.536864
------------------------------------------------------------------------------

. test jc + univ <0
+ not found
r(111);

. test jc+ univ<0
+ not found
r(111);

. test jc < univ
< not found
r(111);

. test jc + univ < 0
+ not found
r(111);

. reg lwage jc totcoll exper stotal

      Source |       SS       df       MS              Number of obs =    6763
-------------+------------------------------           F(  4,  6758) =  500.23
       Model |  367.406831     4  91.8517079           Prob > F      =  0.0000
    Residual |  1240.88926  6758  .183617825           R-squared     =  0.2284
-------------+------------------------------           Adj R-squared =  0.2280
       Total |  1608.29609  6762  .237843255           Root MSE      =  .42851

------------------------------------------------------------------------------
       lwage |      Coef.   Std. Err.      t    P>|t|     [95% Conf. Interval]
-------------+----------------------------------------------------------------
          jc |  -.0055892   .0069385    -0.81   0.421    -.0191909    .0080126
     totcoll |   .0686405   .0025651    26.76   0.000     .0636121     .073669
       exper |   .0048773   .0001571    31.04   0.000     .0045692    .0051854
      stotal |   .0493766   .0068096     7.25   0.000     .0360277    .0627255
       _cons |   1.495271   .0212176    70.47   0.000     1.453678    1.536864
------------------------------------------------------------------------------

. gen stotalsq = stotal * stotal

. reg lwage jc univ exper stotal stotalsq

      Source |       SS       df       MS              Number of obs =    6763
-------------+------------------------------           F(  5,  6757) =  400.17
       Model |  367.436832     5  73.4873664           Prob > F      =  0.0000
    Residual |  1240.85926  6757  .183640559           R-squared     =  0.2285
-------------+------------------------------           Adj R-squared =  0.2279
       Total |  1608.29609  6762  .237843255           Root MSE      =  .42853

------------------------------------------------------------------------------
       lwage |      Coef.   Std. Err.      t    P>|t|     [95% Conf. Interval]
-------------+----------------------------------------------------------------
          jc |   .0632092    .006833     9.25   0.000     .0498143    .0766041
        univ |   .0685131   .0025846    26.51   0.000     .0634466    .0735797
       exper |   .0048776   .0001572    31.04   0.000     .0045695    .0051857
      stotal |   .0501562   .0070778     7.09   0.000     .0362814     .064031
    stotalsq |   .0019191   .0047481     0.40   0.686    -.0073886    .0112268
       _cons |    1.49399   .0214545    69.64   0.000     1.451932    1.536047
------------------------------------------------------------------------------

. gen jcstotal = jc*stotal

. gen univtotal = univ*stotal

. reg lwage jc univ exper stotal jctotal univtotal
variable jctotal not found
r(111);

. reg lwage jc univ exper stotal jcstotal univtotal

      Source |       SS       df       MS              Number of obs =    6763
-------------+------------------------------           F(  6,  6756) =  334.24
       Model |  368.126196     6  61.3543661           Prob > F      =  0.0000
    Residual |   1240.1699  6756  .183565704           R-squared     =  0.2289
-------------+------------------------------           Adj R-squared =  0.2282
       Total |  1608.29609  6762  .237843255           Root MSE      =  .42845

------------------------------------------------------------------------------
       lwage |      Coef.   Std. Err.      t    P>|t|     [95% Conf. Interval]
-------------+----------------------------------------------------------------
          jc |    .063636   .0068983     9.22   0.000     .0501132    .0771588
        univ |   .0689706   .0027439    25.14   0.000     .0635917    .0743494
       exper |   .0048856   .0001572    31.08   0.000     .0045775    .0051938
      stotal |   .0582108   .0087001     6.69   0.000     .0411559    .0752657
    jcstotal |  -.0168818    .009275    -1.82   0.069    -.0350638    .0013001
   univtotal |  -.0026652   .0029894    -0.89   0.373    -.0085254     .003195
       _cons |   1.495924   .0212432    70.42   0.000      1.45428    1.537567
------------------------------------------------------------------------------

. test jcstotal univtotal

 ( 1)  jcstotal = 0
 ( 2)  univtotal = 0

       F(  2,  6756) =    1.96
            Prob > F =    0.1410

. * not jointly significant

. reg lwage jc univ exper stotal

      Source |       SS       df       MS              Number of obs =    6763
-------------+------------------------------           F(  4,  6758) =  500.23
       Model |  367.406832     4  91.8517079           Prob > F      =  0.0000
    Residual |  1240.88926  6758  .183617825           R-squared     =  0.2284
-------------+------------------------------           Adj R-squared =  0.2280
       Total |  1608.29609  6762  .237843255           Root MSE      =  .42851

------------------------------------------------------------------------------
       lwage |      Coef.   Std. Err.      t    P>|t|     [95% Conf. Interval]
-------------+----------------------------------------------------------------
          jc |   .0630514   .0068214     9.24   0.000     .0496792    .0764235
        univ |   .0686405   .0025651    26.76   0.000     .0636121     .073669
       exper |   .0048773   .0001571    31.04   0.000     .0045692    .0051854
      stotal |   .0493766   .0068096     7.25   0.000     .0360277    .0627255
       _cons |   1.495271   .0212176    70.47   0.000     1.453678    1.536864
------------------------------------------------------------------------------

. * the original regression is the preferred one

.