Hey!
I seek to evaluate whether participants in an experiment (n=700) who had a BMI above 30 and were randomly assigned to 3 groups with incentives (control group 0€, group1: 150€ and group2: 300€) to lose 6-8% of their body weight had persistent labor market effects over 22 months after the start of the experiment. I have a data set available for this. Using the foreach loop, I would like to find out whether significant differences between the control group and the treatment groups occurred over the three phases of the experiment. For this purpose, I look at the employment status in each phase and subdivide between employed and unemployed. The following code is intended to investigate this. However, I keep getting the error message: "too few ')' or ']' r(132);", even though the number of brackets is clearly sufficient. For the first phase I have the variables treat1_or for group1 and treat2_or for group2.
What am I doing wrong that no data is saved in the desired file folders?
local path "C:\Users\Florian Frankl\Desktop\MA"
global employed_phasen "employment_Abnehmphase employment_Followup employment_Haltephase"
global unemployment_phasen "unemployment_Abnehmphase unemployment_Followup unemployment_Haltephase"
foreach var of varlist $employed_phasen $unemployment_phasen {
local l`var' : variable label `var'
matrix drop _all
reg `var' treat1_or treat2_or if adm_v2==2&drop==0
local pvalue_3x4 = (2 * ttail(e(df_r), abs(_b[treat1_or]/_se[treat1_or])))
local pvalue_3x4 = round(`pvalue_3x4', 0.001)
local pvalue_3x5 = (2 * ttail(e(df_r), abs(_b[treat2_or]/_se[treat2_or])))
local pvalue_3x5 = round(`pvalue_3x5', 0.001)
test treat1_or=treat2_or
local pvalue_diff_3x6=r(p)
local pvalue_diff_3x6=round(`pvalue_diff_3x6',0.001)
local n_a=e(N)
matrix b_a=e(b)
local btreat1_or=round(b_a[1,1],0.001)
matrix se_a=e(V)
local setreat1_or=se_a[1,1]
local setreat1_or=round(sqrt(`setreat1_or'),0.001)
local btreat2_or=round(b_a[1,2],0.001)
local setreat2_or=se_a[2,2]
local setreat2_or=round(sqrt(`setreat2_or'),0.001)
cap drop esam1
cap gen esam1=e(sample)==1
matrix drop _all
mean `var' if control_or==1&esam1==1&drop==0
test `var'
local pvalue_3x2=r(p)
local pvalue_3x2=round(sqrt(`pvalue_3x2'),0.001)
*
local ntreat1_or=e(N)
matrix mtreat1_or=e(b)
local mtreat1_or= mtreat1_or[1,1]
local mtreat1_or=round(`mtreat1_or',0.001)
matrix msetreat1_or=e(V)
local msetreat1_or= msetreat1_or[1,1]
local msetreat1_or=round(sqrt(`msetreat1_or'),0.001)
matrix drop _all
mean `var' if treat2_or==1&esam1==1&drop==0
*
test `var'
local pvalue_3x3=r(p)
local pvalue_3x3=round(sqrt(`pvalue_3x3'),0.001)
*
local ntreat2_or=e(N)
matrix mtreat2_or=e(b)
local mtreat2_or=mtreat2_or[1,1]
local mtreat2_or=round(`mtreat2_or',0.001)
matrix msetreat2_or=e(V)
local msetreat2_or=msetreat2_or[1,1]
local msetreat2_or=round(sqrt(`msetreat2_or'),0.001)
matrix a0`var'=(`mcontrol_or',`mtreat1_or',`mtreat2_or',` btreat1_or',`btreat2_or',. \ `msecontrol_or',`msetreat1_or',`msetreat2_or',`set reat1_or',`setreat2_or',. \ `pvalue_3x1',`pvalue_3x2',`pvalue_3x3',`pvalue_3x4 ',`pvalue_3x5', `pvalue_diff_3x6' \ ///
`ncontrol_or',`ntreat1_or',`ntreat2_or', `n_a',.,. )
matsave a0`var', path("$path\Log-Files\Sub") saving replace
preserve
use "$path\Log-Files\Sub\a0`var'.dta", clear
replace _rowname="a0b_`l`var''" if _rowname=="r1"
replace _rowname="a0se_`l`var''" if _rowname=="r2"
replace _rowname="a0p_`l`var''" if _rowname=="r3"
replace _rowname="a0n_`l`var''" if _rowname=="r4"
save "$path\Log-Files\Sub\a0`var'.dta", replace
use "$path\Tabellen\table_abnehm.dta", clear
append using "$path\Log-Files\Sub\a0`var'.dta"
save "$path\Tabellen\table_abnehm.dta", replace
restore
}
I would be more than thankful to receive any kind of help. Thank you for reading.
Best regards from Germany
I seek to evaluate whether participants in an experiment (n=700) who had a BMI above 30 and were randomly assigned to 3 groups with incentives (control group 0€, group1: 150€ and group2: 300€) to lose 6-8% of their body weight had persistent labor market effects over 22 months after the start of the experiment. I have a data set available for this. Using the foreach loop, I would like to find out whether significant differences between the control group and the treatment groups occurred over the three phases of the experiment. For this purpose, I look at the employment status in each phase and subdivide between employed and unemployed. The following code is intended to investigate this. However, I keep getting the error message: "too few ')' or ']' r(132);", even though the number of brackets is clearly sufficient. For the first phase I have the variables treat1_or for group1 and treat2_or for group2.
What am I doing wrong that no data is saved in the desired file folders?
local path "C:\Users\Florian Frankl\Desktop\MA"
global employed_phasen "employment_Abnehmphase employment_Followup employment_Haltephase"
global unemployment_phasen "unemployment_Abnehmphase unemployment_Followup unemployment_Haltephase"
foreach var of varlist $employed_phasen $unemployment_phasen {
local l`var' : variable label `var'
matrix drop _all
reg `var' treat1_or treat2_or if adm_v2==2&drop==0
local pvalue_3x4 = (2 * ttail(e(df_r), abs(_b[treat1_or]/_se[treat1_or])))
local pvalue_3x4 = round(`pvalue_3x4', 0.001)
local pvalue_3x5 = (2 * ttail(e(df_r), abs(_b[treat2_or]/_se[treat2_or])))
local pvalue_3x5 = round(`pvalue_3x5', 0.001)
test treat1_or=treat2_or
local pvalue_diff_3x6=r(p)
local pvalue_diff_3x6=round(`pvalue_diff_3x6',0.001)
local n_a=e(N)
matrix b_a=e(b)
local btreat1_or=round(b_a[1,1],0.001)
matrix se_a=e(V)
local setreat1_or=se_a[1,1]
local setreat1_or=round(sqrt(`setreat1_or'),0.001)
local btreat2_or=round(b_a[1,2],0.001)
local setreat2_or=se_a[2,2]
local setreat2_or=round(sqrt(`setreat2_or'),0.001)
cap drop esam1
cap gen esam1=e(sample)==1
matrix drop _all
mean `var' if control_or==1&esam1==1&drop==0
test `var'
local pvalue_3x2=r(p)
local pvalue_3x2=round(sqrt(`pvalue_3x2'),0.001)
*
local ntreat1_or=e(N)
matrix mtreat1_or=e(b)
local mtreat1_or= mtreat1_or[1,1]
local mtreat1_or=round(`mtreat1_or',0.001)
matrix msetreat1_or=e(V)
local msetreat1_or= msetreat1_or[1,1]
local msetreat1_or=round(sqrt(`msetreat1_or'),0.001)
matrix drop _all
mean `var' if treat2_or==1&esam1==1&drop==0
*
test `var'
local pvalue_3x3=r(p)
local pvalue_3x3=round(sqrt(`pvalue_3x3'),0.001)
*
local ntreat2_or=e(N)
matrix mtreat2_or=e(b)
local mtreat2_or=mtreat2_or[1,1]
local mtreat2_or=round(`mtreat2_or',0.001)
matrix msetreat2_or=e(V)
local msetreat2_or=msetreat2_or[1,1]
local msetreat2_or=round(sqrt(`msetreat2_or'),0.001)
matrix a0`var'=(`mcontrol_or',`mtreat1_or',`mtreat2_or',` btreat1_or',`btreat2_or',. \ `msecontrol_or',`msetreat1_or',`msetreat2_or',`set reat1_or',`setreat2_or',. \ `pvalue_3x1',`pvalue_3x2',`pvalue_3x3',`pvalue_3x4 ',`pvalue_3x5', `pvalue_diff_3x6' \ ///
`ncontrol_or',`ntreat1_or',`ntreat2_or', `n_a',.,. )
matsave a0`var', path("$path\Log-Files\Sub") saving replace
preserve
use "$path\Log-Files\Sub\a0`var'.dta", clear
replace _rowname="a0b_`l`var''" if _rowname=="r1"
replace _rowname="a0se_`l`var''" if _rowname=="r2"
replace _rowname="a0p_`l`var''" if _rowname=="r3"
replace _rowname="a0n_`l`var''" if _rowname=="r4"
save "$path\Log-Files\Sub\a0`var'.dta", replace
use "$path\Tabellen\table_abnehm.dta", clear
append using "$path\Log-Files\Sub\a0`var'.dta"
save "$path\Tabellen\table_abnehm.dta", replace
restore
}
I would be more than thankful to receive any kind of help. Thank you for reading.
Best regards from Germany
Comment