Notice: On April 23, 2014, Statalist moved from an email list to a forum, based at statalist.org.
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
st: mata within the loop does not work
From
Oleksandr Shepotylo <[email protected]>
To
[email protected]
Subject
st: mata within the loop does not work
Date
Fri, 14 Jan 2011 11:52:19 +0200
Dear statalist users,
I have the following code to run 500 Monte Carlo iterations
forvalues i=1(1)500 {
use data, clear
...
mata:
fh = fopen("$p\Geography\weights\weighting_matrix_short", "r")
W=fgetmatrix(fh)
sigma_e=st_numscalar("sigma2")
rho=st_numscalar("rho")
uhat=(I(9)#luinv(I(129)-rho*W))*rnormal(1161, 1, 0, sigma_e)
fclose(fh)
end
...
}
The loop never starts and I get the error r(1). Here is what I got on
the screen:
forvalues i=1(1)100 {
2.
. use `panel1', clear
3.
. mata:
4. fh = fopen("$p\Geography\weights\weighting_matrix_short", "r")
5. W=fgetmatrix(fh)
6. sigma_e=st_numscalar("sigma2")
7. rho=st_numscalar("rho")
8. uhat=(I(9)#luinv(I(129)-rho*W))*rnormal(1161, 1, 0, sigma_e)
9. fclose(fh)
10. end
--Break--
r(1);
It seems that Stata does not want to enter Mata mode. If I remove the
loop and run just one iteration everything works fine. If I take out
the mata part of the code from the loop, the loop runs fine as well. I
also tried using foreach instead and it does not work.
Any help would be greatly appreciated.
Best,
--
Oleksandr Shepotylo
Kyiv School of Economics
Web Page shepotylo.kse.org.ua
Blog shepotylo.blogspot.com
*
* For searches and help try:
* http://www.stata.com/help.cgi?search
* http://www.stata.com/support/statalist/faq
* http://www.ats.ucla.edu/stat/stata/