Hello everyone,
I've been attempting to encapsulate a sequence of statistical analysis and simulation steps into a custom Stata program. The goal is to streamline the invocation of repetitive analyses. However, after encapsulating and invoking the program, I encountered two main issues: an error related to a missing temporary file, and a non-symmetric corr() matrix error. Here is the core part of my encapsulated program:
********
program define simulate_scenario
args correlation placebo_3m placebo_12m intervention_3m intervention_12m
clear
tempname char
tempfile char_file
postfile `char' reps p3m_int p12m_int p3m_tot p12m_tot using `char_file', replace
local nsize = 2200
local interimsize = 750
local alpha = 0.05
local reps = 10
local seed = 1000
local n = 1
while `n' <= `reps' {
clear
* Example rbinary command
rbinary pain3m pain12m, means(`placebo_3m',`placebo_12m') corr(1,`correlation'\`correlation',1) n(`nsize') seed(`seed')
* Skipping remaining simulation and analysis steps for brevity...
local n=`n'+1
local seed=`seed'+1
post `char' (`n') (`p3m_int') (`p12m_int') (`p3m_tot') (`p12m_tot')
}
postclose `char'
use `char_file', clear
end
********
When attempting to call this program, for example, with:
simulate_scenario 0.33 0.25 0.20 0.146 0.084
I encountered the following error messages:
(file /var/folders/mm/tn03g0v1401d0dd9190q6px80000gn/T//S_72981.000001 not found)
corr() matrix not symmetric
r(505);
It's worth mentioning that when I run the code directly without encapsulation through a program, everything works as expected. It seems the issues arise during the encapsulation process. I suspect it might be related to how temporary files are handled or the construction of the corr() matrix, but I'm unsure how to resolve this.
Has anyone encountered similar issues or have suggestions for dealing with such scenarios? I attach my code
Thanks in advance for your help!
I've been attempting to encapsulate a sequence of statistical analysis and simulation steps into a custom Stata program. The goal is to streamline the invocation of repetitive analyses. However, after encapsulating and invoking the program, I encountered two main issues: an error related to a missing temporary file, and a non-symmetric corr() matrix error. Here is the core part of my encapsulated program:
********
program define simulate_scenario
args correlation placebo_3m placebo_12m intervention_3m intervention_12m
clear
tempname char
tempfile char_file
postfile `char' reps p3m_int p12m_int p3m_tot p12m_tot using `char_file', replace
local nsize = 2200
local interimsize = 750
local alpha = 0.05
local reps = 10
local seed = 1000
local n = 1
while `n' <= `reps' {
clear
* Example rbinary command
rbinary pain3m pain12m, means(`placebo_3m',`placebo_12m') corr(1,`correlation'\`correlation',1) n(`nsize') seed(`seed')
* Skipping remaining simulation and analysis steps for brevity...
local n=`n'+1
local seed=`seed'+1
post `char' (`n') (`p3m_int') (`p12m_int') (`p3m_tot') (`p12m_tot')
}
postclose `char'
use `char_file', clear
end
********
When attempting to call this program, for example, with:
simulate_scenario 0.33 0.25 0.20 0.146 0.084
I encountered the following error messages:
(file /var/folders/mm/tn03g0v1401d0dd9190q6px80000gn/T//S_72981.000001 not found)
corr() matrix not symmetric
r(505);
It's worth mentioning that when I run the code directly without encapsulation through a program, everything works as expected. It seems the issues arise during the encapsulation process. I suspect it might be related to how temporary files are handled or the construction of the corr() matrix, but I'm unsure how to resolve this.
Has anyone encountered similar issues or have suggestions for dealing with such scenarios? I attach my code
Thanks in advance for your help!
Comment