Hi
I am running Stata 15.1 on a Windows 7 8 core desktop. I am trying to run postfile but keep getting the following error
postfile __000000 already exists
The data is one row per individual and a
ID Study HomeMed_affect_drug HomeMed_mood_drug HomeMed_adhd_drug HomeMed_any_psych_drug HomeMed_any_benzo
123 1 1 1 0 1 1
The problematic code is below
version 15.1
tempname handle
loc nlist "HomeMed_affect_drug HomeMed_mood_drug HomeMed_adhd_drug"
di "`nlist'"
foreach x of local nlist {
di "`x'"
forvalues f=1/16 {
postfile `handle' draw `x'_pop `x'_sample_1 `x'_sample_0 `x'_rp using `x'test1 ,replace every(1)
count if `x' ==0 & draw ==`f'
loc `x'_sample_0 =r(N)
count if `x'==1 & draw ==`f'
loc `x'_sample_1= r(N)
count if `x'==1
loc `x'_pop =r(N)
tab `x' study_subject if draw ==`f' |draw ==. ,ex
loc `x'_rp =r(p_exact)
post `handle' (`f') (``x'_pop') ( ``x'_sample_1') (``x'_sample_0') ( ``x'_rp')
}
}
postclose `handle'
I tried inserting a postutil clear statement before the postfile command per a statalist poster but it results in only a single row being posted. A version of this code with just one variable works without problems and saves 16 rows to the posted file.
Has anyone encountered this before and come up with a solution? In the example, I have listed 4 variables but I have more than 4 in the full dataset.
Many thanks
Paul
Paul Walsh
0 Response to Postfile __000000 already exists
Post a Comment