Hi, everyone!
First of all - I am relatively new to Stata, but have learnt some of the basics.
I want to do something that I would presume was quite simple: Create a line graph based on binomial logistic regression result (regression coefficients). There is a small hiccup that is causing me some problems: I want to have to overlayed line graphs – one for women and one for men.
To illustrate my approach based on the auto.dta dataset:
First, I need a log transformation of a variable to be included in the set
gen mpg_log = log(mpg)
logit foreign mpg mpg_log if rep78==3
Logistic regression Number of obs = 30
LR chi2(2) = 8.21
Prob > chi2 = 0.0165
Log likelihood = -5.6493936 Pseudo R2 = 0.4207
------------------------------------------------------------------------------
foreign | Coefficient Std. err. z P>|z| [95% conf. interval]
-------------+----------------------------------------------------------------
mpg | -9.760884 6.677538 -1.46 0.144 -22.84862 3.32685
mpg_log | 235.3801 157.8325 1.49 0.136 -73.96592 544.7261
_cons | -513.3446 340.8593 -1.51 0.132 -1181.417 154.7273
------------------------------------------------------------------------------
logit foreign mpg mpg_log if rep78==4
Logistic regression Number of obs = 18
LR chi2(2) = 13.12
Prob > chi2 = 0.0014
Log likelihood = -5.914538 Pseudo R2 = 0.5260
------------------------------------------------------------------------------
foreign | Coefficient Std. err. z P>|z| [95% conf. interval]
-------------+----------------------------------------------------------------
mpg | -5.140943 4.310988 -1.19 0.233 -13.59032 3.308438
mpg_log | 132.5099 107.5598 1.23 0.218 -78.30356 343.3233
_cons | -295.845 237.7719 -1.24 0.213 -761.8694 170.1793
------------------------------------------------------------------------------
Note: 2 failures and 0 successes completely determined.
Thus far, I have only found one solution:
Simply input the coefficients in a twoway plot using function:
twoway function y=-295.845-5.141*x+132.510*log(x), range(upperlimit1 lowerlimit1) || function y=-513.345-9.761*x+235.380*log(x), range(upperlimit2 lowerlimit2)
I have tried understanding the coefplot command, but can't seem to get it right (I do not have sufficient understanding of STATA to understand how margins really work). It would also be nice to have the option to plot the estimates as points separated by colours (y-scale is log odds, x-scale is mpg).
A slightly more advanced option would be to use the _b[_coef], _b[mpg] and _b[mpg_log] instead of directly entering the numbers after performing the regression, but then I have the problem of entering two different functions in the same graph: _b will just use the latest coefficient estimates, not both separately.
I am sorry if this is something that I should have already found on the forum, but I really can't seem to.
Do anyone have a good solution?
First of all - I am relatively new to Stata, but have learnt some of the basics.
I want to do something that I would presume was quite simple: Create a line graph based on binomial logistic regression result (regression coefficients). There is a small hiccup that is causing me some problems: I want to have to overlayed line graphs – one for women and one for men.
To illustrate my approach based on the auto.dta dataset:
First, I need a log transformation of a variable to be included in the set
gen mpg_log = log(mpg)
logit foreign mpg mpg_log if rep78==3
Logistic regression Number of obs = 30
LR chi2(2) = 8.21
Prob > chi2 = 0.0165
Log likelihood = -5.6493936 Pseudo R2 = 0.4207
------------------------------------------------------------------------------
foreign | Coefficient Std. err. z P>|z| [95% conf. interval]
-------------+----------------------------------------------------------------
mpg | -9.760884 6.677538 -1.46 0.144 -22.84862 3.32685
mpg_log | 235.3801 157.8325 1.49 0.136 -73.96592 544.7261
_cons | -513.3446 340.8593 -1.51 0.132 -1181.417 154.7273
------------------------------------------------------------------------------
logit foreign mpg mpg_log if rep78==4
Logistic regression Number of obs = 18
LR chi2(2) = 13.12
Prob > chi2 = 0.0014
Log likelihood = -5.914538 Pseudo R2 = 0.5260
------------------------------------------------------------------------------
foreign | Coefficient Std. err. z P>|z| [95% conf. interval]
-------------+----------------------------------------------------------------
mpg | -5.140943 4.310988 -1.19 0.233 -13.59032 3.308438
mpg_log | 132.5099 107.5598 1.23 0.218 -78.30356 343.3233
_cons | -295.845 237.7719 -1.24 0.213 -761.8694 170.1793
------------------------------------------------------------------------------
Note: 2 failures and 0 successes completely determined.
Thus far, I have only found one solution:
Simply input the coefficients in a twoway plot using function:
twoway function y=-295.845-5.141*x+132.510*log(x), range(upperlimit1 lowerlimit1) || function y=-513.345-9.761*x+235.380*log(x), range(upperlimit2 lowerlimit2)
I have tried understanding the coefplot command, but can't seem to get it right (I do not have sufficient understanding of STATA to understand how margins really work). It would also be nice to have the option to plot the estimates as points separated by colours (y-scale is log odds, x-scale is mpg).
A slightly more advanced option would be to use the _b[_coef], _b[mpg] and _b[mpg_log] instead of directly entering the numbers after performing the regression, but then I have the problem of entering two different functions in the same graph: _b will just use the latest coefficient estimates, not both separately.
I am sorry if this is something that I should have already found on the forum, but I really can't seem to.
Do anyone have a good solution?
Comment