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
Related Posts with Postfile __000000 already exists
Fine and Gray calculate individual risksDear all, I would like to calculate the 10-year risk of stroke for each individual in my dataset, g…
Problem with variables names inside loopsHi all, I have a set of variables named "ratio_##########_co_###" (where # are numbers). My proble…
Dummy variables in first difference regressionHi guys, I have a potentially very stupid question to ask, but for the life of me I can not figure …
line graphic of series from 1st occurrence Covid-19Hello! I am using the data set provided in this study, "Oxford COVID-19 govt response tracker' here …
Quick question: winsor right only & interactionDear members I have 2 very quick questions. First: I need to winsorize a variable further ONLY on …
Subscribe to:
Post Comments (Atom)
0 Response to Postfile __000000 already exists
Post a Comment