I am running a foreach using a numlist that contains four values, sample sizes for different programs previously defined. My code is as follows:
------- definition of programs somewhere above here ------
matrix M = (., ., ., .\ .,.,.,.\ .,.,.,.\ .,.,.,.)
foreach obs of numlist 50 100 500 1000 {
bias, obs(`obs')
return list
}
before running the foreach I create a matrix M full of missing values, size 4x4, 4 columns for the different sample sizes and 4 rows for estimator biases that are obtained the program "bias". Is there a way to input said results into a column of the matrix depending on which sample size is currently running? The purpose is to have a full matrix by the end of the loop, but I can't seem to obtain the numbers for the command "matrix M [1,1] = r(something)".
if it's any use, here's the definition of the program bias
program define bias, rclass
drop _all
syntax [, obs(integer 1)]
set obs `obs'
simulate mc0=r(mco0) mc1=r(mco1) iv10=r(ivz10) iv11=r(ivz11) iv20=r(ivz20) ///
iv21=r(ivz21) m_0=r(m0) m_1=r(m1), reps(1000) : IVPGD, obs(`obs')
sum mc1
return scalar b`obs'OLS=r(mean)-1
sum iv11
return scalar b`obs'IV1=r(mean)-1
sum iv21
return scalar b`obs'IV2=r(mean)-1
sum m_1
return scalar b`obs'M=r(mean)-1
end
------- definition of programs somewhere above here ------
matrix M = (., ., ., .\ .,.,.,.\ .,.,.,.\ .,.,.,.)
foreach obs of numlist 50 100 500 1000 {
bias, obs(`obs')
return list
}
before running the foreach I create a matrix M full of missing values, size 4x4, 4 columns for the different sample sizes and 4 rows for estimator biases that are obtained the program "bias". Is there a way to input said results into a column of the matrix depending on which sample size is currently running? The purpose is to have a full matrix by the end of the loop, but I can't seem to obtain the numbers for the command "matrix M [1,1] = r(something)".
if it's any use, here's the definition of the program bias
program define bias, rclass
drop _all
syntax [, obs(integer 1)]
set obs `obs'
simulate mc0=r(mco0) mc1=r(mco1) iv10=r(ivz10) iv11=r(ivz11) iv20=r(ivz20) ///
iv21=r(ivz21) m_0=r(m0) m_1=r(m1), reps(1000) : IVPGD, obs(`obs')
sum mc1
return scalar b`obs'OLS=r(mean)-1
sum iv11
return scalar b`obs'IV1=r(mean)-1
sum iv21
return scalar b`obs'IV2=r(mean)-1
sum m_1
return scalar b`obs'M=r(mean)-1
end
Comment