Stata program for Probit/Logit Models


STATA Program for Odds Ratio in Logit Models


Download 230.5 Kb.
bet5/9
Sana23.03.2023
Hajmi230.5 Kb.
#1287378
1   2   3   4   5   6   7   8   9
Bog'liq
STATA Programs

STATA Program for Odds Ratio in Logit Models
natal95.do

* this data set is a small .005 % random sample;


* of observations from the 1995 natality detail;
* data. we will examine the impack of smoking:
* on birth weight. two large states, NY and CA, do not;
* record mothers smoking status. therefore, of the ;
* 4 million births in the US, only 3 million have all;
* the necessary data so there should be 3 million*.005;
* or roughly 15,000 obs;

* set semi colon as the end of line;


# delimit;

* ask it NOT to pause;


set more off;
* open log file;
log using c:\bill\jpsm\natal95.log,replace;

* use the natality detail data set;


use c:\bill\jpsm\natal95;

* print out variable labels;


desc;

* construct indicator for low birth weight;


gen lowbw=birthw<=2500;
label variable lowbw "dummy variable, =1 ifBW<2500 grams";

* get frequencies;


tab lowbw smoked, col row cell;

* run a logit model;


xi: logit lowbw smoked age married i.educ5 i.race4;

* get marginal effects;


mfx compute;

* run a logit but report the odds ratios instead;


xi: logistic lowbw smoked age married i.educ5 i.race4;
log close;
STATA Results for Odds Ratio in Logit Models
natal95.log

------------------------------------------------------------------------------


log: c:\bill\jpsm\natal95.log
log type: text
opened on: 4 Nov 2004, 05:48:05

. * use the natality detail data set;


. use c:\bill\jpsm\natal95;

. * print out variable labels;


. desc;

Contains data from c:\bill\jpsm\natal95.dta


obs: 14,230
vars: 7 27 Oct 2004 14:58
size: 170,760 (98.4% of memory free)
------------------------------------------------------------------------------
> -
storage display value
variable name type format label variable label
------------------------------------------------------------------------------
> -
birthw int %9.0g birth weight in grams
smoked byte %9.0g =1 if mom smoked during
pregnancy
age byte %9.0g moms age at birth
married byte %9.0g =1 if married
race4 byte %9.0g 1=white,2=black,3=asian,4=other
educ5 byte %9.0g 1=0-8, 2=9-11, 3=12, 4=13-15,
5=16+
visits byte %9.0g prenatal visits
------------------------------------------------------------------------------
> -
Sorted by:

. * construct indicator for low birth weight;


. gen lowbw=birthw<=2500;

. label variable lowbw "dummy variable, =1 ifBW<2500 grams";


. * get frequencies;


. tab lowbw smoked, col row cell;

+-------------------+


| Key |
|-------------------|
| frequency |
| row percentage |
| column percentage |
| cell percentage |
+-------------------+

dummy |
variable, |


=1 | =1 if mom smoked
ifBW<2500 | during pregnancy
grams | 0 1 | Total
-----------+----------------------+----------
0 | 11,626 1,745 | 13,371
| 86.95 13.05 | 100.00
| 94.64 89.72 | 93.96
| 81.70 12.26 | 93.96
-----------+----------------------+----------
1 | 659 200 | 859
| 76.72 23.28 | 100.00
| 5.36 10.28 | 6.04
| 4.63 1.41 | 6.04
-----------+----------------------+----------
Total | 12,285 1,945 | 14,230
| 86.33 13.67 | 100.00
| 100.00 100.00 | 100.00
| 86.33 13.67 | 100.00
. * run a logit model;
. xi: logit lowbw smoked age married i.educ5 i.race4;
i.educ5 _Ieduc5_1-5 (naturally coded; _Ieduc5_1 omitted)
i.race4 _Irace4_1-4 (naturally coded; _Irace4_1 omitted)

Iteration 0: log likelihood = -3244.039


Iteration 1: log likelihood = -3149.3534
Iteration 2: log likelihood = -3137.0703
Iteration 3: log likelihood = -3136.9913
Iteration 4: log likelihood = -3136.9912

Logit estimates Number of obs = 14230


LR chi2(10) = 214.10
Prob > chi2 = 0.0000
Log likelihood = -3136.9912 Pseudo R2 = 0.0330

------------------------------------------------------------------------------


lowbw | Coef. Std. Err. z P>|z| [95% Conf. Interval]
-------------+----------------------------------------------------------------
smoked | .6740651 .0897869 7.51 0.000 .4980861 .8500441
age | .0080537 .006791 1.19 0.236 -.0052564 .0213638
married | -.3954044 .0882471 -4.48 0.000 -.5683654 -.2224433
_Ieduc5_2 | -.1949335 .1626502 -1.20 0.231 -.5137221 .1238551
_Ieduc5_3 | -.1925099 .1543239 -1.25 0.212 -.4949791 .1099594
_Ieduc5_4 | -.4057382 .1676759 -2.42 0.016 -.7343769 -.0770994
_Ieduc5_5 | -.3569715 .1780322 -2.01 0.045 -.7059081 -.0080349
_Irace4_2 | .7072894 .0875125 8.08 0.000 .5357681 .8788107
_Irace4_3 | .386623 .307062 1.26 0.208 -.2152075 .9884535
_Irace4_4 | .3095536 .2047899 1.51 0.131 -.0918271 .7109344
_cons | -2.755971 .2104916 -13.09 0.000 -3.168527 -2.343415
------------------------------------------------------------------------------

. * get marginal effects;


. mfx compute;

Marginal effects after logit


y = Pr(lowbw) (predict)
= .05465609
------------------------------------------------------------------------------
variable | dy/dx Std. Err. z P>|z| [ 95% C.I. ] X
---------+--------------------------------------------------------------------
smoked*| .0436744 .00706 6.18 0.000 .029834 .057514 .136683
age | .0004161 .00035 1.19 0.236 -.000271 .001104 26.6564
married*| -.0218806 .0052 -4.21 0.000 -.032074 -.011687 .683204
_Ieduc~2*| -.0095123 .00749 -1.27 0.204 -.024188 .005164 .165495
_Ieduc~3*| -.0096965 .00758 -1.28 0.201 -.024554 .005161 .345397
_Ieduc~4*| -.0190499 .00714 -2.67 0.008 -.033043 -.005057 .22319
_Ieduc~5*| -.0169077 .00771 -2.19 0.028 -.032027 -.001788 .216093
_Irace~2*| .0453844 .00675 6.72 0.000 .032148 .058621 .17168
_Irace~3*| .0236917 .02204 1.07 0.282 -.019506 .06689 .010401
_Irace~4*| .018225 .01363 1.34 0.181 -.008488 .044938 .031694
------------------------------------------------------------------------------
(*) dy/dx is for discrete change of dummy variable from 0 to 1

. * run a logit but report the odds ratios instead;


. xi: logistic lowbw smoked age married i.educ5 i.race4;
i.educ5 _Ieduc5_1-5 (naturally coded; _Ieduc5_1 omitted)
i.race4 _Irace4_1-4 (naturally coded; _Irace4_1 omitted)

Logistic regression Number of obs = 14230


LR chi2(10) = 214.10
Prob > chi2 = 0.0000
Log likelihood = -3136.9912 Pseudo R2 = 0.0330

------------------------------------------------------------------------------


lowbw | Odds Ratio Std. Err. z P>|z| [95% Conf. Interval]
-------------+----------------------------------------------------------------
smoked | 1.962198 .1761796 7.51 0.000 1.645569 2.33975
age | 1.008086 .0068459 1.19 0.236 .9947574 1.021594
married | .6734077 .0594262 -4.48 0.000 .5664506 .8005604
_Ieduc5_2 | .8228894 .1338431 -1.20 0.231 .5982646 1.131852
_Ieduc5_3 | .8248862 .1272996 -1.25 0.212 .6095837 1.116233
_Ieduc5_4 | .6664847 .1117534 -2.42 0.016 .4798043 .9257979
_Ieduc5_5 | .6997924 .1245856 -2.01 0.045 .4936601 .9919973
_Irace4_2 | 2.028485 .1775178 8.08 0.000 1.70876 2.408034
_Irace4_3 | 1.472001 .4519957 1.26 0.208 .8063741 2.687076
_Irace4_4 | 1.362817 .2790911 1.51 0.131 .9122628 2.035893
------------------------------------------------------------------------------

. log close;


log: c:\bill\jpsm\natal95.log
log type: text
closed on: 4 Nov 2004, 05:48:39
------------------------------------------------------------------------------



Download 230.5 Kb.

Do'stlaringiz bilan baham:
1   2   3   4   5   6   7   8   9




Ma'lumotlar bazasi mualliflik huquqi bilan himoyalangan ©fayllar.org 2024
ma'muriyatiga murojaat qiling