Documenti di Didattica
Documenti di Professioni
Documenti di Cultura
. version 9
. * para que stata use sintaxis de version 9 (en caso de tener una versin
posterior)
. set scheme s2manual // modo monocromtico para grficas
. set more off // para que el output del DO file no haga pausa al
correr
.
. tab warm
. *(Working moms can have warm relations with children)
Mom can |
have warm |
relations |
with child | Freq. Percent Cum.
------------+-----------------------------------
1
1SD | 297 12.95 12.95
2D | 723 31.53 44.48
3A | 856 37.33 81.81
4SA | 417 18.19 100.00
------------+-----------------------------------
Total | 2,293 100.00
------------------------------------------------------------------------------
warm | Coef. Std. Err. z P>|z| [95% Conf. Interval]
-------------+----------------------------------------------------------------
male | -.7499562 .0783083 -9.58 0.000 -.9034377 -.5964747
white | -.4127267 .1180436 -3.50 0.000 -.6440879 -.1813655
age | -.0206757 .0024598 -8.41 0.000 -.0254967 -.0158547
ed | .0789344 .0158731 4.97 0.000 .0478238 .1100451
prst | .0066996 .0032863 2.04 0.041 .0002585 .0131408
-------------+----------------------------------------------------------------
/cut1 | -2.466022 .2386009 -2.933671 -1.998373
/cut2 | -.6564482 .2329347 -1.112992 -.1999045
/cut3 | 1.215503 .2335542 .7577454 1.673261
------------------------------------------------------------------------------
------------------------------------------------------------------------------
warm | Coef. Std. Err. z P>|z| [95% Conf. Interval]
-------------+----------------------------------------------------------------
male | -.7589487 .1265685 -6.00 0.000 -1.007018 -.510879
white | -.3579802 .18615 -1.92 0.054 -.7228275 .0068671
age | -.0227585 .0038285 -5.94 0.000 -.0302621 -.0152548
ed | .0421346 .025821 1.63 0.103 -.0084737 .0927429
prst | .0094713 .0049673 1.91 0.057 -.0002645 .019207
-------------+----------------------------------------------------------------
/cut1 | -3.528722 .4055 -4.323487 -2.733957
/cut2 | -1.380973 .3850552 -2.135668 -.6262787
/cut3 | .6297378 .3821996 -.1193596 1.378835
------------------------------------------------------------------------------
.
. * comparando ORDINAL LOGIT con ORDINAL PROBIT
. ologit warm yr89 male white age ed prst, nolog
2
------------------------------------------------------------------------------
warm | Coef. Std. Err. z P>|z| [95% Conf. Interval]
-------------+----------------------------------------------------------------
yr89 | .5239025 .0798988 6.56 0.000 .3673037 .6805013
male | -.7332997 .0784827 -9.34 0.000 -.8871229 -.5794766
white | -.3911595 .1183808 -3.30 0.001 -.6231815 -.1591374
age | -.0216655 .0024683 -8.78 0.000 -.0265032 -.0168278
ed | .0671728 .015975 4.20 0.000 .0358624 .0984831
prst | .0060727 .0032929 1.84 0.065 -.0003813 .0125267
-------------+----------------------------------------------------------------
/cut1 | -2.465362 .2389126 -2.933622 -1.997102
/cut2 | -.630904 .2333155 -1.088194 -.173614
/cut3 | 1.261854 .2340179 .8031873 1.720521
------------------------------------------------------------------------------
------------------------------------------------------------------------------
warm | Coef. Std. Err. z P>|z| [95% Conf. Interval]
-------------+----------------------------------------------------------------
yr89 | .3188147 .0468519 6.80 0.000 .2269867 .4106427
male | -.4170287 .0455459 -9.16 0.000 -.5062971 -.3277603
white | -.2265002 .0694773 -3.26 0.001 -.3626733 -.0903272
age | -.0122213 .0014427 -8.47 0.000 -.0150489 -.0093937
ed | .0387234 .0093241 4.15 0.000 .0204485 .0569982
prst | .003283 .001925 1.71 0.088 -.0004899 .0070559
-------------+----------------------------------------------------------------
/cut1 | -1.428578 .1387742 -1.700571 -1.156586
/cut2 | -.3605589 .1369219 -.6289209 -.092197
/cut3 | .7681637 .1370564 .4995381 1.036789
------------------------------------------------------------------------------
--------------------------------------------------------
Variable | ologit oprobit
-------------------------------+------------------------
warm |
Survey year: 1=1989 0=1977 | 0.524 0.319
| 6.56 6.80
Gender: 1=male 0=female | -0.733 -0.417
| -9.34 -9.16
Race: 1=white 0=not white | -0.391 -0.227
| -3.30 -3.26
Age in years | -0.022 -0.012
| -8.78 -8.47
Years of education | 0.067 0.039
| 4.20 4.15
Occupational prestige | 0.006 0.003
| 1.84 1.71
-------------------------------+------------------------
cut1 |
Constant | -2.465 -1.429
| -10.32 -10.29
3
-------------------------------+------------------------
cut2 |
Constant | -0.631 -0.361
| -2.70 -2.63
-------------------------------+------------------------
cut3 |
Constant | 1.262 0.768
| 5.39 5.60
--------------------------------------------------------
legend: b/t
. * crea una tabla con los modelos previos con tres decimales, t-stats y
etiquetas de variables de hasta 30 caracteres
.
. // Pruebas de hiptesis para coeficientes individuales
. * Wald test
. ologit warm male yr89 white age ed prst, nolog
------------------------------------------------------------------------------
warm | Coef. Std. Err. z P>|z| [95% Conf. Interval]
-------------+----------------------------------------------------------------
male | -.7332997 .0784827 -9.34 0.000 -.8871229 -.5794766
yr89 | .5239025 .0798988 6.56 0.000 .3673037 .6805013
white | -.3911595 .1183808 -3.30 0.001 -.6231815 -.1591374
age | -.0216655 .0024683 -8.78 0.000 -.0265032 -.0168278
ed | .0671728 .015975 4.20 0.000 .0358624 .0984831
prst | .0060727 .0032929 1.84 0.065 -.0003813 .0125267
-------------+----------------------------------------------------------------
/cut1 | -2.465362 .2389126 -2.933622 -1.997102
/cut2 | -.630904 .2333155 -1.088194 -.173614
/cut3 | 1.261854 .2340179 .8031873 1.720521
------------------------------------------------------------------------------
( 1) [warm]male = 0
chi2( 1) = 87.30
Prob > chi2 = 0.0000
.
. display "z*z=" -9.343*-9.343
z*z=87.291649
. return list
scalars:
r(drop) = 0
r(chi2) = 87.30028866314545
r(df) = 1
r(p) = 9.32342950928e-21
4
Ordered logistic regression Number of obs = 2293
LR chi2(6) = 301.72
Prob > chi2 = 0.0000
Log likelihood = -2844.9123 Pseudo R2 = 0.0504
------------------------------------------------------------------------------
warm | Coef. Std. Err. z P>|z| [95% Conf. Interval]
-------------+----------------------------------------------------------------
yr89 | .5239025 .0798988 6.56 0.000 .3673037 .6805013
male | -.7332997 .0784827 -9.34 0.000 -.8871229 -.5794766
white | -.3911595 .1183808 -3.30 0.001 -.6231815 -.1591374
age | -.0216655 .0024683 -8.78 0.000 -.0265032 -.0168278
ed | .0671728 .015975 4.20 0.000 .0358624 .0984831
prst | .0060727 .0032929 1.84 0.065 -.0003813 .0125267
-------------+----------------------------------------------------------------
/cut1 | -2.465362 .2389126 -2.933622 -1.997102
/cut2 | -.630904 .2333155 -1.088194 -.173614
/cut3 | 1.261854 .2340179 .8031873 1.720521
------------------------------------------------------------------------------
------------------------------------------------------------------------------
warm | Coef. Std. Err. z P>|z| [95% Conf. Interval]
-------------+----------------------------------------------------------------
yr89 | .5486813 .0796222 6.89 0.000 .3926246 .704738
white | -.4248955 .1184223 -3.59 0.000 -.656999 -.192792
age | -.0197197 .0024473 -8.06 0.000 -.0245164 -.014923
ed | .0659969 .0159375 4.14 0.000 .03476 .0972337
prst | .0046902 .003286 1.43 0.153 -.0017502 .0111306
-------------+----------------------------------------------------------------
/cut1 | -2.066166 .2337297 -2.524268 -1.608064
/cut2 | -.2697128 .2290783 -.718698 .1792725
/cut3 | 1.566067 .2312319 1.112861 2.019273
------------------------------------------------------------------------------
------------------------------------------------------------------------------
5
warm | Coef. Std. Err. z P>|z| [95% Conf. Interval]
-------------+----------------------------------------------------------------
yr89 | .5239025 .0798988 6.56 0.000 .3673037 .6805013
male | -.7332997 .0784827 -9.34 0.000 -.8871229 -.5794766
white | -.3911595 .1183808 -3.30 0.001 -.6231815 -.1591374
age | -.0216655 .0024683 -8.78 0.000 -.0265032 -.0168278
ed | .0671728 .015975 4.20 0.000 .0358624 .0984831
prst | .0060727 .0032929 1.84 0.065 -.0003813 .0125267
-------------+----------------------------------------------------------------
/cut1 | -2.465362 .2389126 -2.933622 -1.997102
/cut2 | -.630904 .2333155 -1.088194 -.173614
/cut3 | 1.261854 .2340179 .8031873 1.720521
------------------------------------------------------------------------------
. * Wald test
. test age white male
. // Ho: las 3 variables son "conjuntamente insignificantes"
( 1) [warm]age = 0
( 2) [warm]white = 0
( 3) [warm]male = 0
chi2( 3) = 166.62
Prob > chi2 = 0.0000
. * LR test
. ologit warm yr89 male white age ed prst, nolog // modelo completo
------------------------------------------------------------------------------
warm | Coef. Std. Err. z P>|z| [95% Conf. Interval]
-------------+----------------------------------------------------------------
yr89 | .5239025 .0798988 6.56 0.000 .3673037 .6805013
male | -.7332997 .0784827 -9.34 0.000 -.8871229 -.5794766
white | -.3911595 .1183808 -3.30 0.001 -.6231815 -.1591374
age | -.0216655 .0024683 -8.78 0.000 -.0265032 -.0168278
ed | .0671728 .015975 4.20 0.000 .0358624 .0984831
prst | .0060727 .0032929 1.84 0.065 -.0003813 .0125267
-------------+----------------------------------------------------------------
/cut1 | -2.465362 .2389126 -2.933622 -1.997102
/cut2 | -.630904 .2333155 -1.088194 -.173614
/cut3 | 1.261854 .2340179 .8031873 1.720521
------------------------------------------------------------------------------
------------------------------------------------------------------------------
warm | Coef. Std. Err. z P>|z| [95% Conf. Interval]
-------------+----------------------------------------------------------------
yr89 | .5160795 .0792245 6.51 0.000 .3608024 .6713566
ed | .1064872 .014975 7.11 0.000 .0771367 .1358377
6
prst | -.001567 .003212 -0.49 0.626 -.0078624 .0047283
-------------+----------------------------------------------------------------
/cut1 | -.5241726 .158709 -.8352366 -.2131086
/cut2 | 1.22832 .1587648 .9171465 1.539493
/cut3 | 3.016659 .1689551 2.685513 3.347805
------------------------------------------------------------------------------
------------------------------------------------------------------------------
warm | Coef. Std. Err. z P>|z| [95% Conf. Interval]
-------------+----------------------------------------------------------------
yr89 | .5239025 .0798988 6.56 0.000 .3673037 .6805013
male | -.7332997 .0784827 -9.34 0.000 -.8871229 -.5794766
white | -.3911595 .1183808 -3.30 0.001 -.6231815 -.1591374
age | -.0216655 .0024683 -8.78 0.000 -.0265032 -.0168278
ed | .0671728 .015975 4.20 0.000 .0358624 .0984831
prst | .0060727 .0032929 1.84 0.065 -.0003813 .0125267
-------------+----------------------------------------------------------------
/cut1 | -2.465362 .2389126 -2.933622 -1.997102
/cut2 | -.630904 .2333155 -1.088194 -.173614
/cut3 | 1.261854 .2340179 .8031873 1.720521
------------------------------------------------------------------------------
. fitstat
.
.
. // Modelos OLOGIT y el supuesto de las "regresiones paralelas"
. * Los modelos ologit asumen que cada variable X tiene el mismo
. * efecto (positivo o negativo) en cada una de las categoras ordinales
. * de la variable dependiente: X afecta igual la prob(outcome1)
7
. * que prob(outomce2), etc., una vez que ajustamos por cada intercepto
. * o cutpoint.
.
. * generamos datos para ilustrar el supuesto de regresiones paralelas
. clear
. set obs 41
obs was 0, now 41
. gen n = 41-_n
. replace n = (n-20)/2.5
(41 real changes made)
. gen p1 = exp((-1*n)-3.5)/(1+exp((-1*n)-3.5))
. gen p2 = exp((-1*n))/(1+exp((-1*n)))
. gen p3 = exp((-1*n)+2)/(1+exp((-1*n)+2))
. gen x = (n+8)*(9.375)
. label var p1 "Pr(y<=1 | x)"
. label var p2 "Pr(y<=2 | x)"
. label var p3 "Pr(y<=3 | x)"
0 50 100 150
x
Pr(y<=1 | x) Pr(y<=2 | x)
Pr(y<=3 | x)
.
. graph export 05parallel.emf, replace
(file D:\Metodos08\05parallel.emf written in Enhanced Metafile format)
.
. * Una prueba LR aproximada del supuesto de regresiones paralelas
. * (proporcional odds assumption)
.
. * nota: omodel es un comando extra de Stata: findit omodel
.
. sysuse ordwarm2, clear
(77 & 89 General Social Survey)
8
Log likelihood = -2844.9123 Pseudo R2 = 0.0504
------------------------------------------------------------------------------
warm | Coef. Std. Err. z P>|z| [95% Conf. Interval]
-------------+----------------------------------------------------------------
yr89 | .5239025 .0798988 6.56 0.000 .3673037 .6805013
male | -.7332997 .0784827 -9.34 0.000 -.8871229 -.5794766
white | -.3911595 .1183808 -3.30 0.001 -.6231815 -.1591374
age | -.0216655 .0024683 -8.78 0.000 -.0265032 -.0168278
ed | .0671728 .015975 4.20 0.000 .0358624 .0984831
prst | .0060727 .0032929 1.84 0.065 -.0003813 .0125267
-------------+----------------------------------------------------------------
_cut1 | -2.465362 .2389126 (Ancillary parameters)
_cut2 | -.630904 .2333155
_cut3 | 1.261854 .2340179
------------------------------------------------------------------------------
------------------------------------------------------------------------------
warm | Coef. Std. Err. z P>|z| [95% Conf. Interval]
-------------+----------------------------------------------------------------
yr89 | .5239025 .0798988 6.56 0.000 .3673037 .6805013
male | -.7332997 .0784827 -9.34 0.000 -.8871229 -.5794766
white | -.3911595 .1183808 -3.30 0.001 -.6231815 -.1591374
age | -.0216655 .0024683 -8.78 0.000 -.0265032 -.0168278
ed | .0671728 .015975 4.20 0.000 .0358624 .0984831
prst | .0060727 .0032929 1.84 0.065 -.0003813 .0125267
-------------+----------------------------------------------------------------
/cut1 | -2.465362 .2389126 -2.933622 -1.997102
/cut2 | -.630904 .2333155 -1.088194 -.173614
/cut3 | 1.261854 .2340179 .8031873 1.720521
------------------------------------------------------------------------------
. brant, detail
9
-------------+--------------------------
yr89 | 13.01 0.001 2
male | 22.24 0.000 2
white | 1.27 0.531 2
age | 7.38 0.025 2
ed | 4.31 0.116 2
prst | 4.33 0.115 2
----------------------------------------
.
. /*
> brant performs a Brant test of the parallel regression assumption (also
> called the proportional odds assumption) after ologit. The test compares
> slope coefficients of the J-1 binary logits implied by the ordered regression
> model. Stata reports both the results of an omnibus test for the entire
> model and tests of the assumption for each of the independent variables in
> the model.
> */
.
. // Identificando residuales y outliers con predict despus de ologit
.
. sysuse ordwarm2, clear
(77 & 89 General Social Survey)
.
. * regresin logit cuando warm < 2
. logit warmlt2 yr89 male white age ed prst, nolog
------------------------------------------------------------------------------
warmlt2 | Coef. Std. Err. z P>|z| [95% Conf. Interval]
-------------+----------------------------------------------------------------
yr89 | -.9647422 .1542064 -6.26 0.000 -1.266981 -.6625033
male | .3053643 .1291546 2.36 0.018 .052226 .5585025
white | .5526576 .2305396 2.40 0.017 .1008082 1.004507
age | .0164704 .0040571 4.06 0.000 .0085187 .0244221
ed | -.1047962 .0253348 -4.14 0.000 -.1544516 -.0551409
prst | .0014112 .0056702 0.25 0.803 -.0097023 .0125246
_cons | -1.858405 .3958164 -4.70 0.000 -2.63419 -1.082619
------------------------------------------------------------------------------
.
. * regresin logit cuando warm < 3
. logit warmlt3 yr89 male white age ed prst, nolog
10
------------------------------------------------------------------------------
warmlt3 | Coef. Std. Err. z P>|z| [95% Conf. Interval]
-------------+----------------------------------------------------------------
yr89 | -.5654063 .0928433 -6.09 0.000 -.7473757 -.3834368
male | .6905423 .0898786 7.68 0.000 .5143834 .8667012
white | .3142708 .1405978 2.24 0.025 .0387042 .5898374
age | .0253345 .0028644 8.84 0.000 .0197203 .0309486
ed | -.0528527 .0184571 -2.86 0.004 -.0890279 -.0166774
prst | -.0095322 .0038184 -2.50 0.013 -.0170162 -.0020482
_cons | -.7303287 .269163 -2.71 0.007 -1.257878 -.202779
------------------------------------------------------------------------------
. predict rstd_lt3, rs
------------------------------------------------------------------------------
warmlt4 | Coef. Std. Err. z P>|z| [95% Conf. Interval]
-------------+----------------------------------------------------------------
yr89 | -.3190732 .1140756 -2.80 0.005 -.5426572 -.0954891
male | 1.083789 .1220668 8.88 0.000 .8445422 1.323035
white | .3929984 .1577582 2.49 0.013 .083798 .7021989
age | .0185905 .0037659 4.94 0.000 .0112096 .0259715
ed | -.0575547 .0253812 -2.27 0.023 -.1073008 -.0078085
prst | -.0055304 .0048413 -1.14 0.253 -.0150193 .0039584
_cons | 1.024517 .3463123 2.96 0.003 .3457571 1.703276
------------------------------------------------------------------------------
. predict rstd_lt4, rs
11
.
.
. // Calculando efectos estandarizados con LISTCOEF
.
. sysuse ordwarm2, clear
(77 & 89 General Social Survey)
------------------------------------------------------------------------------
warm | Coef. Std. Err. z P>|z| [95% Conf. Interval]
-------------+----------------------------------------------------------------
yr89 | .5239025 .0798988 6.56 0.000 .3673037 .6805013
male | -.7332997 .0784827 -9.34 0.000 -.8871229 -.5794766
white | -.3911595 .1183808 -3.30 0.001 -.6231815 -.1591374
age | -.0216655 .0024683 -8.78 0.000 -.0265032 -.0168278
ed | .0671728 .015975 4.20 0.000 .0358624 .0984831
prst | .0060727 .0032929 1.84 0.065 -.0003813 .0125267
-------------+----------------------------------------------------------------
/cut1 | -2.465362 .2389126 -2.933622 -1.997102
/cut2 | -.630904 .2333155 -1.088194 -.173614
/cut3 | 1.261854 .2340179 .8031873 1.720521
------------------------------------------------------------------------------
-------------------------------------------------------------------------------
warm | b z P>|z| bStdX bStdY bStdXY SDofX
-------------+-----------------------------------------------------------------
yr89 | 0.52390 6.557 0.000 0.2566 0.2699 0.1322 0.4897
male | -0.73330 -9.343 0.000 -0.3658 -0.3778 -0.1885 0.4989
white | -0.39116 -3.304 0.001 -0.1287 -0.2015 -0.0663 0.3290
age | -0.02167 -8.778 0.000 -0.3635 -0.0112 -0.1873 16.7790
ed | 0.06717 4.205 0.000 0.2123 0.0346 0.1094 3.1608
prst | 0.00607 1.844 0.065 0.0880 0.0031 0.0453 14.4923
-------------------------------------------------------------------------------
b = raw coefficient
z = z-score for test of b=0
P>|z| = p-value for z-test
bStdX = x-standardized coefficient
bStdY = y-standardized coefficient
bStdXY = fully standardized coefficient
SDofX = standard deviation of X
.
. // Graficando probabilidades predichas con predict
.
. ologit warm yr89 male white age ed prst, nolog
12
Log likelihood = -2844.9123 Pseudo R2 = 0.0504
------------------------------------------------------------------------------
warm | Coef. Std. Err. z P>|z| [95% Conf. Interval]
-------------+----------------------------------------------------------------
yr89 | .5239025 .0798988 6.56 0.000 .3673037 .6805013
male | -.7332997 .0784827 -9.34 0.000 -.8871229 -.5794766
white | -.3911595 .1183808 -3.30 0.001 -.6231815 -.1591374
age | -.0216655 .0024683 -8.78 0.000 -.0265032 -.0168278
ed | .0671728 .015975 4.20 0.000 .0358624 .0984831
prst | .0060727 .0032929 1.84 0.065 -.0003813 .0125267
-------------+----------------------------------------------------------------
/cut1 | -2.465362 .2389126 -2.933622 -1.997102
/cut2 | -.630904 .2333155 -1.088194 -.173614
/cut3 | 1.261854 .2340179 .8031873 1.720521
------------------------------------------------------------------------------
.
. dotplot SDwarm Dwarm Awarm SAwarm, ylabel(0(.25).75) ///
> ysize(2.0124) xsize(3.039)
.75
.5
.25
0
.
. // Calculando probabilidades predichas para casos particulares con PRVALUE
.
. ologit warm yr89 male white age ed prst, nolog
------------------------------------------------------------------------------
warm | Coef. Std. Err. z P>|z| [95% Conf. Interval]
-------------+----------------------------------------------------------------
yr89 | .5239025 .0798988 6.56 0.000 .3673037 .6805013
male | -.7332997 .0784827 -9.34 0.000 -.8871229 -.5794766
13
white | -.3911595 .1183808 -3.30 0.001 -.6231815 -.1591374
age | -.0216655 .0024683 -8.78 0.000 -.0265032 -.0168278
ed | .0671728 .015975 4.20 0.000 .0358624 .0984831
prst | .0060727 .0032929 1.84 0.065 -.0003813 .0125267
-------------+----------------------------------------------------------------
/cut1 | -2.465362 .2389126 -2.933622 -1.997102
/cut2 | -.630904 .2333155 -1.088194 -.173614
/cut3 | 1.261854 .2340179 .8031873 1.720521
------------------------------------------------------------------------------
.
. * Un obrero de 64 aos encuestado en 1977
. prvalue, x(yr89=0 male=1 prst=20 age=64 ed=16) rest(mean)
.
. * Una joven de 1989 muy educada y con un empleo muy prestigioso
. prvalue, x(yr89=1 male=0 prst=80 age=30 ed=24) rest(mean)
.
. * Un individuo promedio encuestado en 1977
. prvalue, x(yr89=0) rest(mean) brief
. * la opcin brief presenta un output resumido de prvalue
.
. * Un individuo promedio encuestado en 1989
. prvalue, x(yr89=1) rest(mean) brief
14
95% Conf. Interval
Pr(y=1SD|x): 0.0837 [ 0.0711, 0.0963]
Pr(y=2D|x): 0.2802 [ 0.2571, 0.3032]
Pr(y=3A|x): 0.4277 [ 0.4046, 0.4507]
Pr(y=4SA|x): 0.2085 [ 0.1855, 0.2315]
.
. // Tablas de probabilidades predichas con PRTAB
.
. prtab yr89 male, novarlbl
.
. * prtab no incluye intervalos de confianza, para obtenerlos
. * hay que usar prvalue:
.
. prvalue, x(yr89=0 male=1)
15
Confidence intervals by delta method
.
. // Cambios discretos con Intervalos de confianza
.
. * Hombres vs. mujeres
. prvalue , x(male=0 yr89=1) rest(mean) save // guarda la estimacin
16
. * Efecto de aumentar la edad en una desviacin estndar
. * centrada en torno a la edad promedio (44.93)
.
. display 44.935 - (.5*16.779)
36.5455
.
. prvalue, x(male=0 yr89=1 age=36.5455) rest(mean) save
.
. // Graficando una serie de probabilidades predichas con PRGEN
.
. prgen age, from(20) to(80) generate(w89) x(male=0 yr89=1) ncases(13)
. * Probabilidades predichas para edades de 20 a 80 aos, usando
. * mujeres encuestadas en 1989 como lnea de base.
. * Las 13 predicciones se guardan en una serie de variables con el prefijo
"w89"
. desc w89*
17
w89p1 float %9.0g pr(1SD)=Pr(1)
w89p2 float %9.0g pr(2D)=Pr(2)
w89p3 float %9.0g pr(3A)=Pr(3)
w89p4 float %9.0g pr(4SA)=Pr(4)
w89s1 float %9.0g pr(y<=1)
w89s2 float %9.0g pr(y<=2)
w89s3 float %9.0g pr(y<=3)
w89s4 float %9.0g pr(y<=4)
20 30 40 50 60 70 80
Age
SD D
A SA
.
. * Paso 2: Grfica de probabilidades acumuladas
. graph twoway connected w89s1 w89s2 w89s3 w89x, ///
> title("Panel B: Cumulative Probabilities") ///
> xtitle("Age") xlabel(20(10)80) ylabel(0(.25)1) xline(44.93) ///
> yscale(noline) ylabel("") name(tmp2, replace) ///
> ytitle("")
18
Panel B: Cumulative Probabilities
20 30 40 50 60 70 80
Age
SD SD or D
SD, D or A
.
. * Paso 3: combinar las grficas guardadas en memoria
. graph combine tmp1 tmp2, col(1) iscale(*.9) imargin(small) ///
> ysize(4.31) xsize(3.287)
20 30 40 50 60 70 80
Age
SD D
A SA
20 30 40 50 60 70 80
Age
SD SD or D
SD, D or A
.
. * Paso 4: Guardar grfica en formato "enhanced metafile"
. graph export 05prgen.emf, replace
(file D:\Metodos08\05prgen.emf written in Enhanced Metafile format)
.
.
. // Calculando cambios en probabilidades predichas con PRCHANGE
. ologit warm yr89 male white age ed prst, nolog
19
LR chi2(6) = 301.72
Prob > chi2 = 0.0000
Log likelihood = -2844.9123 Pseudo R2 = 0.0504
------------------------------------------------------------------------------
warm | Coef. Std. Err. z P>|z| [95% Conf. Interval]
-------------+----------------------------------------------------------------
yr89 | .5239025 .0798988 6.56 0.000 .3673037 .6805013
male | -.7332997 .0784827 -9.34 0.000 -.8871229 -.5794766
white | -.3911595 .1183808 -3.30 0.001 -.6231815 -.1591374
age | -.0216655 .0024683 -8.78 0.000 -.0265032 -.0168278
ed | .0671728 .015975 4.20 0.000 .0358624 .0984831
prst | .0060727 .0032929 1.84 0.065 -.0003813 .0125267
-------------+----------------------------------------------------------------
/cut1 | -2.465362 .2389126 -2.933622 -1.997102
/cut2 | -.630904 .2333155 -1.088194 -.173614
/cut3 | 1.261854 .2340179 .8031873 1.720521
------------------------------------------------------------------------------
.
. * Efectos marginales usando prchange (comando Spost)
. prchange age, x(male=0 yr89=1) rest(mean) help
age
Avg|Chg| 1SD 2D 3A 4SA
Min->Max .16441458 .10941909 .21941006 -.05462247 -.27420671
-+1/2 .00222661 .00124099 .00321223 -.0001803 -.00427291
-+sd/2 .0373125 .0208976 .05372739 -.00300205 -.07162295
MargEfct .00222662 .00124098 .00321226 -.00018032 -.00427292
1SD 2D 3A 4SA
Pr(y|x) .06099996 .22815652 .44057754 .27026597
.
. * Efectos marginales usando mfx (comando stata)
. mfx compute, at(male=0 yr89=1) predict(outcome(1))
20
---------+--------------------------------------------------------------------
yr89*| -.0378526 .00601 -6.30 0.000 -.049633 -.026072 1
male*| .0581355 .00731 7.95 0.000 .043803 .072468 0
white*| .0197511 .0055 3.59 0.000 .008972 .03053 .876581
age | .001241 .00016 7.69 0.000 .000925 .001557 44.9355
ed | -.0038476 .00097 -3.96 0.000 -.005754 -.001941 12.2181
prst | -.0003478 .00019 -1.83 0.068 -.000721 .000025 39.5853
------------------------------------------------------------------------------
(*) dy/dx is for discrete change of dummy variable from 0 to 1
.
. * Efectos marginales de cambios discretos con prchange
. prchange male age prst, x(male=0 yr89=1) rest(mean) help
male
Avg|Chg| 1SD 2D 3A 4SA
0->1 .08469636 .05813552 .11125721 -.05015317 -.11923955
age
Avg|Chg| 1SD 2D 3A 4SA
Min->Max .16441458 .10941909 .21941006 -.05462247 -.27420671
-+1/2 .00222661 .00124099 .00321223 -.0001803 -.00427291
-+sd/2 .0373125 .0208976 .05372739 -.00300205 -.07162295
MargEfct .00222662 .00124098 .00321226 -.00018032 -.00427292
prst
Avg|Chg| 1SD 2D 3A 4SA
Min->Max .04278038 -.02352008 -.06204067 .00013945 .08542132
-+1/2 .00062411 -.00034784 -.00090037 .00005054 .00119767
-+sd/2 .00904405 -.00504204 -.01304607 .00073212 .01735598
MargEfct .00062411 -.00034784 -.00090038 .00005054 .00119767
1SD 2D 3A 4SA
Pr(y|x) .06099996 .22815652 .44057754 .27026597
.
. * Efecto marginal de un aumento de 10 aos en edad
. * (usando la opcin delta de prchange)
. quietly ologit warm yr89 male white age ed prst, nolog
(Note: d = 10)
21
age
Avg|Chg| 1SD 2D 3A 4SA
Min->Max .16441458 .10941909 .21941006 -.05462247 -.27420671
-+d/2 .02225603 .01242571 .03208634 -.00179818 -.04271388
-+sd/2 .0373125 .0208976 .05372739 -.00300205 -.07162295
MargEfct .00222662 .00124098 .00321226 -.00018032 -.00427292
1SD 2D 3A 4SA
Pr(y|x) .06099996 .22815652 .44057754 .27026597
.
.
. // Mostrar odds ratios con LISTCOEF
.
. ologit warm yr89 male white age ed prst, nolog
------------------------------------------------------------------------------
warm | Coef. Std. Err. z P>|z| [95% Conf. Interval]
-------------+----------------------------------------------------------------
yr89 | .5239025 .0798988 6.56 0.000 .3673037 .6805013
male | -.7332997 .0784827 -9.34 0.000 -.8871229 -.5794766
white | -.3911595 .1183808 -3.30 0.001 -.6231815 -.1591374
age | -.0216655 .0024683 -8.78 0.000 -.0265032 -.0168278
ed | .0671728 .015975 4.20 0.000 .0358624 .0984831
prst | .0060727 .0032929 1.84 0.065 -.0003813 .0125267
-------------+----------------------------------------------------------------
/cut1 | -2.465362 .2389126 -2.933622 -1.997102
/cut2 | -.630904 .2333155 -1.088194 -.173614
/cut3 | 1.261854 .2340179 .8031873 1.720521
------------------------------------------------------------------------------
----------------------------------------------------------------------
warm | b z P>|z| e^b e^bStdX SDofX
-------------+--------------------------------------------------------
male | -0.73330 -9.343 0.000 0.4803 0.6936 0.4989
22
age | -0.02167 -8.778 0.000 0.9786 0.6952 16.7790
----------------------------------------------------------------------
b = raw coefficient
z = z-score for test of b=0
P>|z| = p-value for z-test
e^b = exp(b) = factor change in odds for unit increase in X
e^bStdX = exp(b*SD of X) = change in odds for SD increase in X
SDofX = standard deviation of X
----------------------------------------------------------------------
warm | b z P>|z| % %StdX SDofX
-------------+--------------------------------------------------------
male | -0.73330 -9.343 0.000 -52.0 -30.6 0.4989
age | -0.02167 -8.778 0.000 -2.1 -30.5 16.7790
----------------------------------------------------------------------
b = raw coefficient
z = z-score for test of b=0
P>|z| = p-value for z-test
% = percent change in odds for unit increase in X
%StdX = percent change in odds for SD increase in X
SDofX = standard deviation of X
----------------------------------------------------------------------
warm | b z P>|z| e^b e^bStdX SDofX
-------------+--------------------------------------------------------
male | -0.73330 -9.343 0.000 2.0819 1.4417 0.4989
----------------------------------------------------------------------
b = raw coefficient
z = z-score for test of b=0
P>|z| = p-value for z-test
e^b = exp(b) = factor change in odds for unit increase in X
e^bStdX = exp(b*SD of X) = change in odds for SD increase in X
SDofX = standard deviation of X
.
. log close
log: D:\MyDocs\Metodos08\Long&FreeseSpost9\ch5_ordinal.log
log type: text
closed on: 30 Nov 2008, 20:45:37
23
DO FILE
version 9
* para que stata use sintaxis de version 9 (en caso de tener una versin
posterior)
set scheme s2manual // modo monocromtico para grficas
set more off // para que el output del DO file no haga pausa al correr
tab warm
* Var. Dep.: Est de acuerdo o no con la frase?
* "Las mams que trabajan pueden mantener relaciones calidas con sus hijos"
ologit warm male white age ed prst if yr89==1, nolog // muestra restringida
* Wald test
ologit warm male yr89 white age ed prst, nolog
test male // test similar al z-score de la tabla
24
display "z*z=" -9.343*-9.343
return list
di "chi2=" r(chi2) "; sqrt(chi2)= " sqrt(r(chi2))
* Wald test
test age white male
// Ho: las 3 variables son "conjuntamente insignificantes"
* LR test
ologit warm yr89 male white age ed prst, nolog // modelo completo
estimates store fmodel
25
ysize(2.6558) xsize(4.0413)
/*
brant performs a Brant test of the parallel regression assumption (also
called the proportional odds assumption) after ologit. The test compares
slope coefficients of the J-1 binary logits implied by the ordered regression
model. Stata reports both the results of an omnibus test for the entire
model and tests of the assumption for each of the independent variables in
the model.
*/
26
listcoef, std help
27
prvalue, x(male=0 yr89=1 age=36.5455) rest(mean) save
prvalue, x(male=0 yr89=1 age=53.3245) rest(mean) dif
desc w89*
label var w89p1 "SD" // prob(outcome1)
label var w89p2 "D" // prob(outcome2)
label var w89p3 "A" // prob(outcome3)
label var w89p4 "SA" // prob(outcome4)
label var w89s1 "SD"
label var w89s2 "SD or D" // probabilidad acumulada
label var w89s3 "SD, D or A" // probabilidad acumulada
28
quietly ologit warm yr89 male white age ed prst, nolog
prchange age, x(male=0 yr89=1) rest(mean) delta(10) help
log close
29