Created
November 18, 2015 21:44
-
-
Save puterleat/2009b99abb68946fae91 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
. do "/var/folders/47/f2b3zfds1y5gq4vp7m6___cr0000gn/T//SD44048.000000" | |
. clear all | |
. set seed 123 | |
. | |
. * recruit subjects (if only this easy...) | |
. set obs 2000 | |
number of observations (_N) was 0, now 2,000 | |
. | |
. * assign to groups | |
. gen mbct = mod(_n, 2) | |
. | |
. * depression baseline score | |
. gen d0 = rnormal(0,1) | |
. | |
. * generate probability of relapse note - no interaction term here | |
. gen p = max(min(.5*d0 + .3*mbct, .99), 0.01) | |
. | |
. | |
. gen y = rbinomial(1,p) | |
. summ y | |
Variable | Obs Mean Std. Dev. Min Max | |
-------------+--------------------------------------------------------- | |
y | 2,000 .2875 .4527099 0 1 | |
. | |
. * ns interaction term in the logistic regression | |
. logistic y mbct##c.d0 | |
Logistic regression Number of obs = 2,000 | |
LR chi2(3) = 1054.64 | |
Prob > chi2 = 0.0000 | |
Log likelihood = -672.47361 Pseudo R2 = 0.4395 | |
------------------------------------------------------------------------------ | |
y | Odds Ratio Std. Err. z P>|z| [95% Conf. Interval] | |
-------------+---------------------------------------------------------------- | |
1.mbct | 3.006289 .5619068 5.89 0.000 2.084166 4.336399 | |
d0 | 11.49553 2.036777 13.78 0.000 8.122942 16.2684 | |
| | |
mbct#c.d0 | | |
1 | 1.545352 .3948197 1.70 0.088 .9366024 2.549762 | |
| | |
_cons | .0959822 .0144456 -15.57 0.000 .0714632 .1289137 | |
------------------------------------------------------------------------------ | |
. | |
. * but get ES estimates in probability domainfo 1 SD above and below mean baseline | |
. margins, dydx(mbct) at(d0=(-1(1)1)) | |
Conditional marginal effects Number of obs = 2,000 | |
Model VCE : OIM | |
Expression : Pr(y), predict() | |
dy/dx w.r.t. : 1.mbct | |
1._at : d0 = -1 | |
2._at : d0 = 0 | |
3._at : d0 = 1 | |
------------------------------------------------------------------------------ | |
| Delta-method | |
| dy/dx Std. Err. z P>|z| [95% Conf. Interval] | |
-------------+---------------------------------------------------------------- | |
1.mbct | | |
_at | | |
1 | .007703 .0048014 1.60 0.109 -.0017077 .0171136 | |
2 | .1363576 .0227078 6.00 0.000 .0918512 .1808641 | |
3 | .3121895 .0367425 8.50 0.000 .2401756 .3842033 | |
------------------------------------------------------------------------------ | |
Note: dy/dx for factor levels is the discrete change from the base level. | |
. | |
. | |
end of do-file | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment