Hi Stata listers
Looking for insight into an odd error. The file below runs correctly when executed as a do from a do file window but returns
r(9611)
OR
foreach ifs1 in `if1' {
program 0while already defined
r(110);
r(110);
interchangeably when run as an ado file. The include command calls another do file which uses the locals (strv indv etc)
In the code I migrated the globals to locals from user input to splice with the existing code of the included do file and also to try and weed out the problem if it was related to global and local issues.
The included do file is not buggy and has worked for several months properly so I don't suspect that.
My hunch is that it is something to do with the translation from global to local and that the ado vs do execution has some subtle difference in the referencing of these macros?
Any insight would be appreciated.
cheers
Darren
************************************************** *************************************************
program cubeit
clear
macro drop _all
display"Enter Dataset type Adult=1 Child=2: "_request(rdstyp)
display"Enter dataset year: "_request(rdsyr)
display"Enter weight variable: "_request(rwtvar)
display"Enter categorical=1 or continuous=2 variables: "_request(rcatcon)
display"Enter vari list: "_request(rvaril)
display"Enter strat list: "_request(rstratl)
display"Enter if1 list (default is dumif): "_request(rif1l)
display"Enter if2 list (default is dumif): "_request(rif2l)
display"Enter if3 list (default is dumif): "_request(rif3l)
display"Enter geographies: "_request(rgeogl)
*migrate globals to locals and align names to the compiler code
local strv $rstratl
local indv $rvaril
local if1 dumif $rif1l
local if2 dumif $rif2l
local if3 dumif $rif3l
local dsyr $rdsyr
local geov $rgeogl
local date=c(current_date)
local dstyp=$rdstyp
local catcon=$rcatcon
*+"_"+ c(current_time)
macro list
if `dstyp'==1 {
use "Q:\STATA\Surveys\master_data\urfs\SRHS`dsyr'_Mast er", clear
}
*
if `dstyp'==2 {
use "Q:\STATA\Surveys\master_data\urfs\CHS`dsyr'_Maste r", clear
}
*
svyset [pweight=$rwtvar]
gen dumif=90
gen state=300000
label drop _all
if `catcon'==1 {
include "Q:\STATA\Surveys\est_db\CUBE 2.0\datacube\code\static_code\cube2compiler_catvar .do"
}
*
if `catcon'==2 {
include "Q:\STATA\Surveys\est_db\CUBE 2.0\datacube\code\static_code\cube2compiler_convar .do"
}
*
if `dstyp'==1 {
save "Q:\STATA\Surveys\est_db\cubecompiler\SRHS`dsyr'`d ate'"
}
*
if `dstyp'==2 {
save "Q:\STATA\Surveys\est_db\cubecompiler\CHS`dsyr'`da te'"
}
end
exit
Looking for insight into an odd error. The file below runs correctly when executed as a do from a do file window but returns
r(9611)
OR
foreach ifs1 in `if1' {
program 0while already defined
r(110);
r(110);
interchangeably when run as an ado file. The include command calls another do file which uses the locals (strv indv etc)
In the code I migrated the globals to locals from user input to splice with the existing code of the included do file and also to try and weed out the problem if it was related to global and local issues.
The included do file is not buggy and has worked for several months properly so I don't suspect that.
My hunch is that it is something to do with the translation from global to local and that the ado vs do execution has some subtle difference in the referencing of these macros?
Any insight would be appreciated.
cheers
Darren
************************************************** *************************************************
program cubeit
clear
macro drop _all
display"Enter Dataset type Adult=1 Child=2: "_request(rdstyp)
display"Enter dataset year: "_request(rdsyr)
display"Enter weight variable: "_request(rwtvar)
display"Enter categorical=1 or continuous=2 variables: "_request(rcatcon)
display"Enter vari list: "_request(rvaril)
display"Enter strat list: "_request(rstratl)
display"Enter if1 list (default is dumif): "_request(rif1l)
display"Enter if2 list (default is dumif): "_request(rif2l)
display"Enter if3 list (default is dumif): "_request(rif3l)
display"Enter geographies: "_request(rgeogl)
*migrate globals to locals and align names to the compiler code
local strv $rstratl
local indv $rvaril
local if1 dumif $rif1l
local if2 dumif $rif2l
local if3 dumif $rif3l
local dsyr $rdsyr
local geov $rgeogl
local date=c(current_date)
local dstyp=$rdstyp
local catcon=$rcatcon
*+"_"+ c(current_time)
macro list
if `dstyp'==1 {
use "Q:\STATA\Surveys\master_data\urfs\SRHS`dsyr'_Mast er", clear
}
*
if `dstyp'==2 {
use "Q:\STATA\Surveys\master_data\urfs\CHS`dsyr'_Maste r", clear
}
*
svyset [pweight=$rwtvar]
gen dumif=90
gen state=300000
label drop _all
if `catcon'==1 {
include "Q:\STATA\Surveys\est_db\CUBE 2.0\datacube\code\static_code\cube2compiler_catvar .do"
}
*
if `catcon'==2 {
include "Q:\STATA\Surveys\est_db\CUBE 2.0\datacube\code\static_code\cube2compiler_convar .do"
}
*
if `dstyp'==1 {
save "Q:\STATA\Surveys\est_db\cubecompiler\SRHS`dsyr'`d ate'"
}
*
if `dstyp'==2 {
save "Q:\STATA\Surveys\est_db\cubecompiler\CHS`dsyr'`da te'"
}
end
exit
Comment