Created
November 18, 2015 21:38
-
-
Save puterleat/40d18bcea144c8b1ca41 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 = 1 - min(.5*d0 + .3*mbct, 1) | |
. | |
. summ | |
Variable | Obs Mean Std. Dev. Min Max | |
-------------+--------------------------------------------------------- | |
mbct | 2,000 .5 .500125 0 1 | |
d0 | 2,000 .0203836 .9839001 -4.604603 3.40045 | |
p | 2,000 .851266 .4890847 0 3.302301 | |
. codebook | |
------------------------------------------------------------------------------------------------ | |
mbct (unlabeled) | |
------------------------------------------------------------------------------------------------ | |
type: numeric (float) | |
range: [0,1] units: 1 | |
unique values: 2 missing .: 0/2,000 | |
tabulation: Freq. Value | |
1,000 0 | |
1,000 1 | |
------------------------------------------------------------------------------------------------ | |
d0 (unlabeled) | |
------------------------------------------------------------------------------------------------ | |
type: numeric (float) | |
range: [-4.6046028,3.4004498] units: 1.000e-11 | |
unique values: 2,000 missing .: 0/2,000 | |
mean: .020384 | |
std. dev: .9839 | |
percentiles: 10% 25% 50% 75% 90% | |
-1.21403 -.612031 .012687 .663429 1.23962 | |
------------------------------------------------------------------------------------------------ | |
p (unlabeled) | |
------------------------------------------------------------------------------------------------ | |
type: numeric (float) | |
range: [0,3.3023014] units: 1.000e-10 | |
unique values: 1,901 missing .: 0/2,000 | |
mean: .851266 | |
std. dev: .489085 | |
percentiles: 10% 25% 50% 75% 90% | |
.179416 .496526 .840672 1.17163 1.50491 | |
. | |
. gen y = rbinomial(1,p) | |
(843 missing values generated) | |
. | |
. * ns interaction term in the logistic regression | |
. logistic y mbct##c.d0 | |
Logistic regression Number of obs = 1,157 | |
LR chi2(3) = 379.01 | |
Prob > chi2 = 0.0000 | |
Log likelihood = -596.29243 Pseudo R2 = 0.2412 | |
------------------------------------------------------------------------------ | |
y | Odds Ratio Std. Err. z P>|z| [95% Conf. Interval] | |
-------------+---------------------------------------------------------------- | |
1.mbct | .2666635 .0682103 -5.17 0.000 .1615226 .4402443 | |
d0 | .0737559 .0198726 -9.68 0.000 .0434962 .1250667 | |
| | |
mbct#c.d0 | | |
1 | .919064 .3135055 -0.25 0.805 .4709655 1.793504 | |
| | |
_cons | 10.79623 2.467407 10.41 0.000 6.898198 16.89696 | |
------------------------------------------------------------------------------ | |
. | |
. * 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 = 1,157 | |
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 | -.0162185 .0072951 -2.22 0.026 -.0305166 -.0019204 | |
2 | -.1730282 .0282415 -6.13 0.000 -.2283805 -.1176759 | |
3 | -.2800077 .0394602 -7.10 0.000 -.3573483 -.2026671 | |
------------------------------------------------------------------------------ | |
Note: dy/dx for factor levels is the discrete change from the base level. | |
. | |
. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment