Documentos de Académico
Documentos de Profesional
Documentos de Cultura
L&F Ch5 ModelosOlogit 3nov08
L&F Ch5 ModelosOlogit 3nov08
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
.
.
.
.
.
// muestra completa
Number of obs
LR chi2(5)
Prob > chi2
Pseudo R2
=
=
=
=
2293
258.39
0.0000
0.0431
-----------------------------------------------------------------------------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
-----------------------------------------------------------------------------. * la opcion nolog omite el output de las iteraciones
. ologit warm male white age ed prst if yr89==1, nolog
Ordered logistic regression
Log likelihood = -1083.2871
// muestra restringida
Number of obs
LR chi2(5)
Prob > chi2
Pseudo R2
=
=
=
=
914
91.02
0.0000
0.0403
-----------------------------------------------------------------------------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
Ordered logistic regression
Log likelihood = -2844.9123
Number of obs
LR chi2(6)
Prob > chi2
Pseudo R2
=
=
=
=
2293
301.72
0.0000
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
-----------------------------------------------------------------------------. estimates store ologit
-2848.611
Number of obs
LR chi2(6)
Prob > chi2
Pseudo R2
=
=
=
=
2293
294.32
0.0000
0.0491
-----------------------------------------------------------------------------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
-----------------------------------------------------------------------------. estimates store oprobit
-------------------------------+-----------------------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
Ordered logistic regression
Log likelihood = -2844.9123
Number of obs
LR chi2(6)
Prob > chi2
Pseudo R2
=
=
=
=
2293
301.72
0.0000
0.0504
-----------------------------------------------------------------------------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
-----------------------------------------------------------------------------. test male
( 1)
[warm]male = 0
chi2( 1) =
Prob > chi2 =
87.30
0.0000
.
. display "z*z=" -9.343*-9.343
z*z=87.291649
. return list
scalars:
r(drop)
r(chi2)
r(df)
r(p)
=
=
=
=
0
87.30028866314545
1
9.32342950928e-21
Number of obs
LR chi2(6)
Prob > chi2
Pseudo R2
=
=
=
=
2293
301.72
0.0000
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
-----------------------------------------------------------------------------. estimates store fullmod
. * estimate constrained model
. ologit warm yr89 white age ed prst, nolog
Ordered logistic regression
Log likelihood =
-2889.278
=
=
=
=
2293
212.98
0.0000
0.0355
-----------------------------------------------------------------------------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
-----------------------------------------------------------------------------. estimates store nestedmod
. lrtest fullmod nestedmod
Likelihood-ratio test
(Assumption: nestedmod nested in fullmod)
.
.
.
.
.
LR chi2(1) =
Prob > chi2 =
88.73
0.0000
Number of obs
LR chi2(6)
Prob > chi2
Pseudo R2
=
=
=
=
2293
301.72
0.0000
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
-----------------------------------------------------------------------------. * Wald test
. test age white male
. // Ho: las 3 variables son "conjuntamente insignificantes"
( 1)
( 2)
( 3)
[warm]age = 0
[warm]white = 0
[warm]male = 0
chi2( 3) =
Prob > chi2 =
166.62
0.0000
. * LR test
. ologit warm yr89 male white age ed prst, nolog
Ordered logistic regression
Log likelihood = -2844.9123
// modelo completo
Number of obs
LR chi2(6)
Prob > chi2
Pseudo R2
=
=
=
=
2293
301.72
0.0000
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
-----------------------------------------------------------------------------. estimates store fmodel
. ologit warm yr89 ed prst, nolog
Ordered logistic regression
Log likelihood = -2930.7047
// modelo restringido
Number of obs
LR chi2(3)
Prob > chi2
Pseudo R2
=
=
=
=
2293
130.13
0.0000
0.0217
-----------------------------------------------------------------------------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
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
-----------------------------------------------------------------------------. estimates store nmodel
. lrtest fmodel nmodel
Likelihood-ratio test
(Assumption: nmodel nested in fmodel)
.
.
.
.
.
.
LR chi2(3) =
Prob > chi2 =
171.58
0.0000
Number of obs
LR chi2(6)
Prob > chi2
Pseudo R2
=
=
=
=
2293
301.72
0.0000
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
-----------------------------------------------------------------------------. fitstat
Measures of Fit for ologit of warm
Log-Lik Intercept Only:
D(2284):
McFadden's R2:
ML (Cox-Snell) R2:
McKelvey & Zavoina's R2:
Variance of y*:
Count R2:
AIC:
BIC:
BIC used by Stata:
.
.
.
.
.
.
-2995.770
5689.825
0.050
0.123
0.127
3.768
0.432
2.489
-11982.891
5759.463
-2844.912
301.716
0.000
0.047
0.133
3.290
0.093
5707.825
-255.291
5707.825
.
.
.
.
.
* 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)"
.2
Pr(y<=m)
.4
.6
.8
50
Pr(y<=1 | x)
Pr(y<=3 | x)
100
150
Pr(y<=2 | 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)
. omodel logit warm yr89 male white age ed prst nolog
Ordered logit estimates
Number of obs
LR chi2(6)
Prob > chi2
=
=
=
2293
301.72
0.0000
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
-----------------------------------------------------------------------------Approximate likelihood-ratio test of proportionality of odds
across response categories:
chi2(12) =
48.91
Prob > chi2 =
0.0000
. * Una prueba de Wald del supuesto
. ologit warm yr89 male white age ed prst, nolog
Ordered logistic regression
Number of obs
LR chi2(6)
Prob > chi2
Pseudo R2
=
=
=
=
2293
301.72
0.0000
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
-----------------------------------------------------------------------------. brant, detail
Estimated coefficients from j-1 binary regressions
yr89
male
white
age
ed
prst
_cons
y>1
.9647422
-.30536425
-.55265759
-.0164704
.10479624
-.00141118
1.8584045
y>2
.56540626
-.69054232
-.31427081
-.02533448
.05285265
.00953216
.73032873
y>3
.31907316
-1.0837888
-.39299842
-.01859051
.05755466
.00553043
-1.0245168
-------------+-------------------------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
---------------------------------------A significant test statistic provides evidence that the parallel
regression assumption has been violated.
.
. /*
> 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
Logistic regression
Log likelihood = -819.61992
Number of obs
LR chi2(6)
Prob > chi2
Pseudo R2
=
=
=
=
2293
128.58
0.0000
0.0727
-----------------------------------------------------------------------------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
-----------------------------------------------------------------------------. predict rstd_lt2, rs
.
. * regresin logit cuando warm < 3
. logit warmlt3 yr89 male white age ed prst, nolog
Logistic regression
Log likelihood = -1449.7863
Number of obs
LR chi2(6)
Prob > chi2
Pseudo R2
=
=
=
=
2293
251.23
0.0000
0.0797
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
. * regresin logit cuando < 4
. logit warmlt4 yr89 male white age ed prst, nolog
Logistic regression
Number of obs
LR chi2(6)
Prob > chi2
Pseudo R2
=
=
=
=
2293
150.77
0.0000
0.0693
-----------------------------------------------------------------------------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
* graficando los residuales cuando warm < 3
sort prst
// ordena los datos de acuerdo a prestigio
gen index = _n // genera un ndice de 1 al nmero de obs.
// (para el eje horizontal de la grfica)
graph twoway scatter rstd_lt3 index, yline(0) ylabel(-4(2)4) ///
xtitle("Observation Number") xlabel(0(500)2293) ///
ysize(2.6558) xsize(4.0413) msymbol(Oh)
-4
.
.
.
.
.
.
>
>
2500
500
1000
1500
Observation Number
2000
11
.
.
. // Calculando efectos estandarizados con LISTCOEF
.
. sysuse ordwarm2, clear
(77 & 89 General Social Survey)
. ologit warm yr89 male white age ed prst, nolog
Ordered logistic regression
Log likelihood = -2844.9123
Number of obs
LR chi2(6)
Prob > chi2
Pseudo R2
=
=
=
=
2293
301.72
0.0000
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
-----------------------------------------------------------------------------. listcoef, std help
ologit (N=2293): Unstandardized and Standardized Estimates
Observed SD: .9282156
Latent SD: 1.9410634
------------------------------------------------------------------------------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
Ordered logistic regression
Number of obs
LR chi2(6)
Prob > chi2
=
=
=
2293
301.72
0.0000
12
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
-----------------------------------------------------------------------------. predict SDwarm Dwarm Awarm SAwarm
(option pr assumed; predicted probabilities)
.
.
.
.
.
.25
.5
.75
.
. dotplot SDwarm Dwarm Awarm SAwarm, ylabel(0(.25).75) ///
>
ysize(2.0124) xsize(3.039)
Pr(SD)
Pr(D)
Pr(A)
Pr(SA)
Number of obs
LR chi2(6)
Prob > chi2
Pseudo R2
=
=
=
=
2293
301.72
0.0000
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
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)
ologit: Predictions for warm
Confidence intervals by delta method
Pr(y=1SD|x):
Pr(y=2D|x):
Pr(y=3A|x):
Pr(y=4SA|x):
x=
yr89
0
0.2317
0.4221
0.2723
0.0739
male
1
white
.8765809
age
64
ed
16
prst
20
.
. * 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)
ologit: Predictions for warm
Confidence intervals by delta method
Pr(y=1SD|x):
Pr(y=2D|x):
Pr(y=3A|x):
Pr(y=4SA|x):
x=
yr89
1
0.0164
0.0781
0.3147
0.5908
male
0
white
.8765809
age
30
ed
24
prst
80
.
. * Un individuo promedio encuestado en 1977
. prvalue, x(yr89=0) rest(mean) brief
. * la opcin brief presenta un output resumido de prvalue
ologit: Predictions for warm
Pr(y=1SD|x):
Pr(y=2D|x):
Pr(y=3A|x):
Pr(y=4SA|x):
0.1336
0.3577
0.3737
0.1349
.
. * Un individuo promedio encuestado en 1989
. prvalue, x(yr89=1) rest(mean) brief
ologit: Predictions for warm
14
Pr(y=1SD|x):
Pr(y=2D|x):
Pr(y=3A|x):
Pr(y=4SA|x):
0.0837
0.2802
0.4277
0.2085
.
. // Tablas de probabilidades predichas con PRTAB
.
. prtab yr89 male, novarlbl
. * Tabula las diferentes combinaciones de yr89 y male
. * en una tabla 2x2 (porque ambas son dummies)
ologit: Predicted probabilities for warm
Predicted probability of outcome 1 (1SD)
-------------------------|
male
yr89 | Women
Men
----------+--------------1977 | 0.0989 0.1859
1989 | 0.0610 0.1191
-------------------------Predicted probability of outcome 2 (2D)
-------------------------|
male
yr89 | Women
Men
----------+--------------1977 | 0.3083 0.4026
1989 | 0.2282 0.3394
-------------------------Predicted probability of outcome 3 (3A)
-------------------------|
male
yr89 | Women
Men
----------+--------------1977 | 0.4129 0.3162
1989 | 0.4406 0.3904
-------------------------Predicted probability of outcome 4 (4SA)
-------------------------|
male
yr89 | Women
Men
----------+--------------1977 | 0.1799 0.0953
1989 | 0.2703 0.1510
-------------------------x=
yr89
.39860445
male
.46489315
white
.8765809
age
44.935456
ed
12.218055
prst
39.585259
.
. * prtab no incluye intervalos de confianza, para obtenerlos
. * hay que usar prvalue:
.
. prvalue, x(yr89=0 male=1)
ologit: Predictions for warm
15
x=
0.1859
0.4026
0.3162
0.0953
male
1
white
.8765809
age
44.935456
ed
12.218055
prst
39.585259
x=
0.0610
0.2282
0.4406
0.2703
male
0
white
.8765809
age
44.935456
ed
12.218055
prst
39.585259
.
. // Cambios discretos con Intervalos de confianza
.
. * Hombres vs. mujeres
. prvalue , x(male=0 yr89=1) rest(mean) save // guarda la estimacin
ologit: Predictions for warm
Confidence intervals by delta method
Pr(y=1SD|x):
Pr(y=2D|x):
Pr(y=3A|x):
Pr(y=4SA|x):
yr89
1
x=
0.0610
0.2282
0.4406
0.2703
male
0
white
.8765809
age
44.935456
ed
12.218055
prst
39.585259
yr89
1
1
0
Current
0.1191
0.3394
0.3904
0.1510
male
1
0
1
Saved
0.0610
0.2282
0.4406
0.2703
Change
0.0581
0.1113
-0.0502
-0.1192
white
.8765809
.8765809
0
age
44.935456
44.935456
0
ed
12.218055
12.218055
0
prst
39.585259
39.585259
0
16
x=
0.0514
0.2019
0.4392
0.3076
male
0
white
.8765809
age
36.5455
ed
12.218055
prst
39.585259
Current
0.0723
0.2556
0.4362
0.2359
yr89
1
1
0
Current=
Saved=
Diff=
male
0
0
0
Saved
0.0514
0.2019
0.4392
0.3076
Change
0.0209
0.0537
-0.0030
-0.0716
white
.8765809
.8765809
0
age
53.3245
36.5455
16.779
ed
12.218055
12.218055
0
prst
39.585259
39.585259
0
.
. // 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"
ologit: Predicted values as age varies from 20 to 80.
x=
yr89
1
male
0
white
.8765809
age
44.935456
ed
12.218055
prst
39.585259
. desc w89*
storage display
value
variable name
type
format
label
variable label
------------------------------------------------------------------------------w89x
float %9.0g
Age in years
17
w89p1
w89p2
w89p3
w89p4
w89s1
w89s2
w89s3
w89s4
.
.
.
.
.
.
.
label
label
label
label
label
label
label
float
float
float
float
float
float
float
float
var
var
var
var
var
var
var
w89p1
w89p2
w89p3
w89p4
w89s1
w89s2
w89s3
%9.0g
%9.0g
%9.0g
%9.0g
%9.0g
%9.0g
%9.0g
%9.0g
pr(1SD)=Pr(1)
pr(2D)=Pr(2)
pr(3A)=Pr(3)
pr(4SA)=Pr(4)
pr(y<=1)
pr(y<=2)
pr(y<=3)
pr(y<=4)
"SD" // prob(outcome1)
"D"
// prob(outcome2)
"A"
// prob(outcome3)
"SA" // prob(outcome4)
"SD"
"SD or D" // probabilidad acumulada
"SD, D or A" // probabilidad acumulada
20
30
40
50
Age
SD
A
60
70
80
D
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
20
30
40
50
Age
SD
SD, D or A
60
70
80
SD or D
.
. * Paso 3: combinar las grficas guardadas en memoria
. graph combine tmp1 tmp2, col(1) iscale(*.9) imargin(small) ///
>
ysize(4.31) xsize(3.287)
Panel A: Predicted Probabilities
20
30
40
50
Age
60
SD
SA
70
80
70
80
20
30
40
50
Age
SD
60
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
Ordered logistic regression
Number of obs
2293
19
LR chi2(6)
Prob > chi2
Pseudo R2
=
=
=
301.72
0.0000
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
ologit: Changes in Probabilities for warm
age
Avg|Chg|
.16441458
.00222661
.0373125
.00222662
Min->Max
-+1/2
-+sd/2
MargEfct
Pr(y|x)
x=
sd(x)=
1SD
.06099996
yr89
1
.489718
1SD
.10941909
.00124099
.0208976
.00124098
2D
.22815652
male
0
.498875
2D
.21941006
.00321223
.05372739
.00321226
3A
.44057754
white
.876581
.328989
3A
-.05462247
-.0001803
-.00300205
-.00018032
4SA
-.27420671
-.00427291
-.07162295
-.00427292
age
44.9355
16.779
4SA
.27026597
ed
12.2181
3.16083
prst
39.5853
14.4923
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
ologit: Changes in Probabilities for warm
male
0->1
Avg|Chg|
.08469636
1SD
.05813552
2D
.11125721
3A
-.05015317
4SA
-.11923955
Min->Max
-+1/2
-+sd/2
MargEfct
Avg|Chg|
.16441458
.00222661
.0373125
.00222662
1SD
.10941909
.00124099
.0208976
.00124098
2D
.21941006
.00321223
.05372739
.00321226
3A
-.05462247
-.0001803
-.00300205
-.00018032
4SA
-.27420671
-.00427291
-.07162295
-.00427292
Avg|Chg|
.04278038
.00062411
.00904405
.00062411
1SD
-.02352008
-.00034784
-.00504204
-.00034784
2D
-.06204067
-.00090037
-.01304607
-.00090038
3A
.00013945
.00005054
.00073212
.00005054
4SA
.08542132
.00119767
.01735598
.00119767
age
prst
Min->Max
-+1/2
-+sd/2
MargEfct
Pr(y|x)
x=
sd(x)=
1SD
.06099996
yr89
1
.489718
2D
.22815652
male
0
.498875
3A
.44057754
white
.876581
.328989
age
44.9355
16.779
4SA
.27026597
ed
12.2181
3.16083
prst
39.5853
14.4923
21
age
Avg|Chg|
.16441458
.02225603
.0373125
.00222662
Min->Max
-+d/2
-+sd/2
MargEfct
Pr(y|x)
x=
sd(x)=
1SD
.06099996
1SD
.10941909
.01242571
.0208976
.00124098
yr89
1
.489718
2D
.22815652
male
0
.498875
2D
.21941006
.03208634
.05372739
.00321226
3A
.44057754
white
.876581
.328989
3A
-.05462247
-.00179818
-.00300205
-.00018032
4SA
-.27420671
-.04271388
-.07162295
-.00427292
age
44.9355
16.779
4SA
.27026597
ed
12.2181
3.16083
prst
39.5853
14.4923
Number of obs
LR chi2(6)
Prob > chi2
Pseudo R2
=
=
=
=
2293
301.72
0.0000
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
-----------------------------------------------------------------------------. listcoef male age, help
ologit (N=2293): Factor Change in Odds
Odds of: >m vs <=m
---------------------------------------------------------------------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
. listcoef male age, percent help
ologit (N=2293): Percentage Change in Odds
Odds of: >m vs <=m
---------------------------------------------------------------------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
. listcoef male, reverse help
ologit (N=2293): Factor Change in Odds
Odds of: <=m vs >m
---------------------------------------------------------------------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:
log type:
closed on:
D:\MyDocs\Metodos08\Long&FreeseSpost9\ch5_ordinal.log
text
30 Nov 2008, 20:45:37
23
DO FILE
capture log close
log using ch5_ordinal, replace
* crea una bitcora con formato de texto plano
//
//
//
//
//
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
*
*
*
*
// muestra restringida
* Wald test
ologit warm male yr89 white age ed prst, nolog
test male
// test similar al z-score de la tabla
24
// modelo completo
// modelo restringido
25
ysize(2.6558) xsize(4.0413)
graph export 05parallel.emf, replace
* 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
omodel logit warm yr89 male white age ed prst
* Una prueba de Wald del supuesto
ologit warm yr89 male white age ed prst, nolog
brant, detail
/*
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
var
var
var
var
SDwarm "Pr(SD)"
Dwarm "Pr(D)"
Awarm "Pr(A)"
SAwarm "Pr(SA)"
//
//
//
//
prob(Strongly
prob(Strongly
prob(Strongly
prob(Strongly
Disagree)
Disagree)
Disagree)
Agree)
27
w89p1
w89p2
w89p3
w89p4
w89s1
w89s2
w89s3
"SD" // prob(outcome1)
"D"
// prob(outcome2)
"A"
// prob(outcome3)
"SA" // prob(outcome4)
"SD"
"SD or D" // probabilidad acumulada
"SD, D or A" // probabilidad acumulada
28
29