Hi everyone. I need some help with the Declare Design code. I am trying to investigate a within-subjects experimental design with two treatments (T1 and T2). Covariate W determines whether participants respond to T2 or not. I am running an interaction effect between Z and W. I have tried various solutions, but none of them seem to work. This is my latest try:
nrespondents <- 100 bZ <- 0 # A parameter to model the difference between t1 and t2 bW <- 0 bWZ <- 0.5 within_subjects <- declare_model(respondent_treatment = add_level(N = 2, Z = c(0,1)), respondents = add_level(N = nrespondents, u=rnorm(N), W=draw_binary(prob=.5,N=nrespondents), nest = FALSE), observations = cross_levels( by = join(Z,respondents), Y = bZ*Z + bW*W + bWZ*W*Z + u )) + declare_inquiry(ate = mean(Y_Z_1 - Y_Z_0), interaction=bWZ) + # we are interested in the effect of Z on Y1 declare_estimator(Y ~ Z, model = lm_robust, cluster = respondents, label = "within") + declare_estimator(Y ~ Z*W, model = lm_robust, cluster = respondents, label = "with interaction", inquiry = c("ate", "interaction"))
If I diagnose this design i get this error: Error: Error in step 2 (inquiry):
Error in mean(Y_Z_1 - Y_Z_0): object ‘Y_Z_1’ not found
I appreciate any feedback on this.