



Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
This page cannot be seen from the preview
Don't miss anything!




sociology logistic regression example
The data for this example come from the 1985 cps. The y variable, called rich , is a dummy coded 1 if hourly wage is in the 90 th^ percentile or above, 0 otherwise.
Let’s begin by fitting the linear probability model. This is just a simple regression:
1. regress rich edyrs
Source | SS df MS Number of obs = 515 ---------+------------------------------ F( 1, 513) = 45. Model | 3.31257874 1 3.31257874 Prob > F = 0. Residual | 37.7553824 513 .073597237 R-squared = 0. ---------+------------------------------ Adj R-squared = 0. Total | 41.0679612 514 .079898757 Root MSE =.
rich | Coef. Std. Err. t P>|t| [95% Conf. Interval] ---------+-------------------------------------------------------------------- edyrs | .0336817 .0050204 6.709 0.000 .0238186. _cons | -.3569582 .067301 -5.304 0.000 -.4891777 -.
Now let’s get the fitted probabilities of being rich for each year of schooling:
2. predict lpm_prob (option xb assumed; fitted values)
Note that “lpm_prob” is the name I chose for the variable that holds the fitted probabilities.
3. tab edyrs,summ(lpm_prob)
years of | Summary of Fitted values schooling | Mean Std. Dev. Freq. ------------+------------------------------------ 8.00 | -.08750459 0 15 9.00 | -.05382289 0 12 10.00 | -.02014119 0 17 11.00 | .01354051 0 27 12.00 | .04722221. 215 13.00 | .08090391 0 36 14.00 | .11458561 0 55 15.00 | .1482673 0 13 16.00 | .181949. 70 17.00 | .2156307 0 24 18.00 | .2493124 0 31 ------------+------------------------------------ Total | .08737864 .08027892 515
Notice that three of the fitted “probabilities” are negative. This won’t happen when we fit the logistic.
Here’s the logistic model:
4. logit rich edyrs
Logit estimates Number of obs = 515 LR chi2(1) = 40. Prob > chi2 = 0. Log likelihood = -132.26951 Pseudo R2 = 0.
rich | Coef. Std. Err. z P>|z| [95% Conf. Interval] ---------+-------------------------------------------------------------------- edyrs | .4272412 .071766 5.953 0.000 .2865824. _cons | -8.405214 1.095768 -7.671 0.000 -10.55288 -6.
stata gives the coefficient .427 on the log-odds scale. we can ask stata to produced a fitted equation for this model, in which case it will give a fitted log_odds of being rich for each year of schooling. Here it is:
. predict lg_odds,xb . tab edyrs,summ(lg_odds)
years of | Summary of Linear prediction schooling | Mean Std. Dev. Freq. ------------+------------------------------------ 8.00 | -4.9872842 0 15 9.00 | -4.5600429 0 12 10.00 | -4.132802 0 17 11.00 | -3.7055607 0 27 12.00 | -3.2783196. 215 13.00 | -2.8510783 0 36 14.00 | -2.4238372 0 55 15.00 | -1.9965959 0 13 16.00 | -1.5693547. 70 17.00 | -1.1421134 0 24 18.00 | -.7148723 0 31 ------------+------------------------------------ Total | -2.7689485 1.0183116 515
Well, there’s not much to be said about this except that the log odds of being rich increase by .427 for each year of schooling.
Now let’s look at the graph of the fitted log-odds against schooling: it should be a straight line with slope .427 and intercept -8.40.
**6. gen odds=exp(lg_odds)
years of | Summary of odds schooling | Mean Std. Dev. Freq. ------------+------------------------------------ 8.00 | .00682417 0 15 9.00 | .01046161 0 12 10.00 | .01603788 0 17 11.00 | .02458643 0 27 12.00 | .03769154 0 215 13.00 | .05778198 0 36 14.00 | .08858106 0 55 15.00 | .13579677 0 13 16.00 | .20817949. 70 17.00 | .3191438 0 24 18.00 | .48925459 0 31 ------------+------------------------------------ Total | .1075426 .12523981 515
This would be a good time to make sure you know how to use the exponential function on your calculator. For example, you should find that if you take the log-odds of being rich for 15 years of schooling, -1.9965959, you can convert it to the fitted plain odds, .13579677. Hence, exp(-1.9965...)= .135796...
This would also be a good time to get an intuitive feel for the formula:
Odds ratio = exp(B) = exp(.4272412) = 1.
Notice that for any two years of schooling values that are one year apart, the ratio of the odds of being rich at the higher schooling value to the odds at the lower value equals 1.53.
Now let’s graph the fitted plain odds. They will not graph as a straight line against schooling; they will graph as an exponential function.
8. graph odds edyrs
Remember that earlier I ran the model logit rich edyrs. Since I haven’t fit any other models since then, stata knows that when I issue the following command, I am referring to that earlier model and asking for the fitted probabilities.
9. predict prob,p
“prob” is the name that I chose for the variable that holds the fitted probabilities.
10. tab edyrs,summ(prob)
years of | Summary of Pr(rich) schooling | Mean Std. Dev. Freq. ------------+------------------------------------ 8.00 | .00677792 0 15 9.00 | .0103533 0 12 10.00 | .01578473 0 17 11.00 | .02399644 0 27 12.00 | .03632249. 215 13.00 | .0546256 0 36 14.00 | .08137297 0 55 15.00 | .11956079 0 13 16.00 | .1723084. 70 17.00 | .24193253 0 24 18.00 | .32852313 0 31 ------------+------------------------------------ Total | .08737864 .08665454 515
You should convince yourself that you could compute these fitted probabilities by hand from the original logit output. For exmaple, suppose I want the estimated probability that someone with 15 years of schooling is rich. The first thing I do is compute the fitted logodds of being rich at 15 years of schooling. From what we did above, that figure is -1.9965959. Then we do the following:
Prob(rich/15years)= exp(-1.9965959)/(1+exp(-1.9965959) = .13579677/(1+ .13579677) =.
(note that the numerator of the probability is just the plain odds of being rich that was computed above.)
Now let’s graph the fitted probabilities against schooling. The curve will be a logistic, although......