Error message: “st_matrixcolstripe(): 3300 argument out of range katya(): – function returned error : – function returned error”
this code appears to perform a statistical analysis, involving maximum entropy estimation, on data from multiple years. It calculates weights for observations based on constraints and potentially optimizes a model by iteratively adjusting parameters. This was written by someone else and they are very busy, where do I probe for errors? For your reference, this is what the code for MATA looks like:
do "$path/gidd programs/Mata Select reweight targets.do"
ds c1f00-c3m70
* Call Mata Function
mata: katya("r(varlist)") // The Katya Function
drop const
svmat Q0, names(matcol)
local f_varlist ""
foreach var of varlist c1f00 - c3f75 {
capture confirm variable Q0`var'
if !_rc {
local f_varlist "`f_varlist' `var'"
}
else {
drop `var'
}
}
drop Q0*
if "`foreign'"!="" matrix define Y = (Y `foreign')
svmat Y, names(col)
rename c1 const
if "`foreign'"!="" {
merge 1:1 idh using `foreigndb'
drop _merge
noi di "Maxentropy for year `a'"
noi di "The constraint matrix for year `a'"
matrix list const`a'
noi di "`country'"
noi di "maxentropy const `f_varlist' foreign, prior(`iweights') generate(newwgt) total(`tsumpop`a'') "
cap maxentropy const `f_varlist' ___foreign, prior(`iweights') generate(newwgt) total(`tsumpop`a'')
if !_rc {
gen newiwgt = newwgt/hhsize
keep `id' newiwgt
clonevar idh_merge = `id'
sort idh_merge
tempfile max`a'
save `max`a'', replace
local a = `a' + `stp'
}
else {
noi di "Convergence not achieved at alpha: " $sc_alpha
global sc_alpha = $sc_alpha * 10
noi di ""
noi di "New alpha: " $sc_alpha
}
}
if "`foreign'"=="" {
noi di "Maxentropy for year `a'"
noi di "The constraint matrix for year `a'"
matrix list const`a'
noi di "`country'"
noi di "maxentropy const `f_varlist' , prior(`iweights') generate(newwgt) total(`tsumpop`a'') "
cap maxentropy const `f_varlist' , prior(`iweights') generate(newwgt) total(`tsumpop`a'')
if !_rc {
gen newiwgt = newwgt/hhsize
keep `id' newiwgt
clonevar idh_merge = `id'
sort idh_merge
tempfile max`a'
save `max`a'', replace
local a = `a' + `stp'
}
else {
noi di "Convergence not achieved at alpha: " $sc_alpha
global sc_alpha = $sc_alpha * 10
noi di ""
noi di "New alpha: " $sc_alpha
}
}
restore
}
use `base', clear
forval a = `iyear'(`stp')`tyear' {
clonevar idh_merge = `id'
sort idh_merge
merge m:1 idh_merge using `max`a''
tab _merge
drop _merge
sort idh_merge
drop idh_merge
gen double `generate'`a' = newiwgt
drop newiwgt
}
}
end
The do file called above has the following:
version 12
clear mata
mata:
void katya(string scalar variables)
{
varnames=tokens(st_global(variables))
x=st_data(., ("c1f00 - c3m70"))
y=st_data(., "const")
submat = select(y, rowmissing(y):< $sc_alpha)
z = select(x',submat:>= $sc_alpha)'
q = select(submat,submat:>= $sc_alpha)
colnames=select(varnames',submat:>= $sc_alpha)
colnames=J(rows(colnames),1,""), colnames
q0 = select(q ,rowsum(z'):>= $sc_alpha)
colnames0 = select(colnames,rowsum(z'):>= $sc_alpha)
qnull = select(q ,rowsum(z'):< $sc_alpha)'
colnull = select(colnames, rowsum(z'):< $sc_alpha)
q0_ = q0'
st_matrix("Q0",q0_)
st_matrixcolstripe("Q0", colnames0)
st_matrix("Y", q0)
}
end
Gauri is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.