Hi all,
I'd like to simulate some data (for a power analysis) that performs a logit with an interaction between two dummies/dichotomous predictors ('group' and 'task'). Below is a minimal reproducible example. Task is a repeated measure variable (i.e., each participant complete both tasks).
Currently my simulation is set up so that performance on the dv is uncorrelated across the two tasks, but I'd like to set it up so that the two are correlated (at 0.40). I couldn't figure out how to do this, and would be grateful for any suggestions.
I'd like to simulate some data (for a power analysis) that performs a logit with an interaction between two dummies/dichotomous predictors ('group' and 'task'). Below is a minimal reproducible example. Task is a repeated measure variable (i.e., each participant complete both tasks).
Currently my simulation is set up so that performance on the dv is uncorrelated across the two tasks, but I'd like to set it up so that the two are correlated (at 0.40). I couldn't figure out how to do this, and would be grateful for any suggestions.
Code:
set seed 98765
program define myprog, rclass
clear
set obs 400
gen id = _n
gen group = runiformint(0,1)
gen dv1 = rbinomial(1,.625) if group == 0
replace dv1 = rbinomial(1,.325) if group == 1
gen dv2 = rbinomial(1,.58)
reshape long dv, i(id) j(task)
logit dv i.group##i.task, cluster(id)
margins task, dydx(group) pwcompare(effects) post
lincom _b[1.group:1.task]
return scalar diffdiff = r(estimate)
return scalar p = r(p)
end
simulate diffdiff = r(diffdiff) p = r(p), reps(10000) nodots: myprog

Comment