Is there a maximum number of local macros allowed in Stata? Or: What is the maximum number of local macros the SSC program tuples can generate?
The following syntax creates the 80 local macros `tuple1' to `tuple80' as intended:
However, if I de-comment lines 1-3 and comment out lines 5-7 instead, tuples first stops running and subequently Stata crashes. I know that 1,900 local macros are really a lot. If this is not possible, I will continue with a follow-up question explaining the purpose to see whether there is an alternative solution to my task.
The following syntax creates the 80 local macros `tuple1' to `tuple80' as intended:
Code:
local px "05 10 15 20"
local py "05 10 15 20"
local r "50 55 60 65 70"
* local py = "02.5 05 10 15 20 25 30 45 50 55"
* local px = "02.5 05 10 15 20 25 30 45 50 55"
* local r = "05 10 15 20 25 30 35 40 45 50 55 60 65 70 75 80 85 90 95"
local notupx2 ""
tuples `px', min(2) max(2)
forvalues t = 1/`ntuples' {
local el = 0
foreach n of local px {
local ++el
local num = `el'
local tuple`t' = subinstr("`tuple`t''","`n'","`num'",.)
}
local tuple`t' = subinstr("`tuple`t''"," ","&",.)
local notupx2 "`notupx2' !(`tuple`t'')"
}
* local notupx2 = strtrim("`notupx2'")
local plus = `num'
di "`notupx2'"
local notupy2 ""
tuples `py', min(2) max(2)
forvalues t = 1/`ntuples' {
local el = 0
foreach n of local py {
local ++el
local num = `el'+`plus'
local tuple`t' = subinstr("`tuple`t''","`n'","`num'",.)
}
local tuple`t' = subinstr("`tuple`t''"," ","&",.)
local notupy2 "`notupy2' !(`tuple`t'')"
}
* local notupy2 = strtrim("`notupy2'")
local plus = `num'
local notupr2 ""
tuples `r', min(2) max(2)
forvalues t = 1/`ntuples' {
local el = 0
foreach n of local r {
local ++el
local num = `el'+`plus'
local tuple`t' = subinstr("`tuple`t''","`n'","`num'",.)
}
local tuple`t' = subinstr("`tuple`t''"," ","&",.)
local notupr2 "`notupr2' !(`tuple`t'')"
}
* local notupr = strtrim("`notupr2'")
* ------------------------------------------------------------------------------
local notupx3 = ""
tuples `px', min(3) max(3)
forvalues t = 1/`ntuples' {
local el = 0
foreach n of local px {
local ++el
local num = `el'
local tuple`t' = subinstr("`tuple`t''","`n'","`num'",.)
}
local tuple`t' = subinstr("`tuple`t''"," ","&",.)
local notupx3 "`notupx3' !(`tuple`t'')"
}
* local notupx3 = strtrim("`notupx3'")
local plus = `num'
local notupy3 = ""
tuples `py', min(3) max(3)
forvalues t = 1/`ntuples' {
local el = 0
foreach n of local py {
local ++el
local num = `el'+`plus'
local tuple`t' = subinstr("`tuple`t''","`n'","`num'",.)
}
local tuple`t' = subinstr("`tuple`t''"," ","&",.)
local notupy3 "`notupy3' !(`tuple`t'')"
}
* local notupy3 = strtrim("`notupy3'")
local plus = `num'
local notupr3 = ""
tuples `r', min(3) max(3)
forvalues t = 1/`ntuples' {
local el = 0
foreach n of local r {
local ++el
local num = `el'+`plus'
local tuple`t' = subinstr("`tuple`t''","`n'","`num'",.)
}
local tuple`t' = subinstr("`tuple`t''"," ","&",.)
local notupr3 "`notupr3' !(`tuple`t'')"
}
* local notupr3 = strtrim("`notupr3'")
* ------------------------------------------------------------------------------
local notupel "`notupx2' `notupx3' `notupy2' `notupy3' `notupr2' `notupr3'"
macro drop _ntup* _tupl* _num _el _plus _notupx* _notupy* _notupr*
* di "`notupel'"
tuples `px' `py' `r' , min(3) max(3) conditionals(`notupel')
macro dir

Comment