Skip to content

Instantly share code, notes, and snippets.

@benwhalley
Created November 16, 2015 17:24
Show Gist options
  • Save benwhalley/58cd6df8f90752471d98 to your computer and use it in GitHub Desktop.
Save benwhalley/58cd6df8f90752471d98 to your computer and use it in GitHub Desktop.
clear all
set seed 123
* recruit subjects (if only this easy...)
set obs 2000
* 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)
gen y = rbinomial(1,p)
* ns interaction term in the logistic regression
logistic y mbct##c.d0
* but get ES estimates in probability domainfo 1 SD above and below mean baseline
margins, dydx(mbct) at(d0=(-1(1)1))
------------------------------------------------------------------------------
| Delta-method
| dy/dx Std. Err. z P>|z| [95% Conf. Interval]
-------------+----------------------------------------------------------------
1.mbct |
_at |
1 | .0162185 .0072951 2.22 0.026 .0019204 .0305166
2 | .1730282 .0282415 6.13 0.000 .1176759 .2283805
3 | .2800077 .0394602 7.10 0.000 .2026671 .3573483
------------------------------------------------------------------------------
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