Stata The Stata listserver
[Date Prev][Date Next][Thread Prev][Thread Next][Date index][Thread index]

st: RE: Including a matrix in a monte carlo simulation


From   "Nick Cox" <[email protected]>
To   <[email protected]>
Subject   st: RE: Including a matrix in a monte carlo simulation
Date   Wed, 16 Oct 2002 20:39:30 +0100

Nevo, Dorit
> 
> I'm trying to calculate the determinant of a matrix within 
> a Monte Carlo
> simulation program. The matrix takes variables that are 
> calculated in
> previous steps in the program.
> 
> The specific command I included is:
> 	matrix H = 
> (0,Fc,Fk,Fl\Fc,Fcc,Fck,Fcl\Fk,Fck,Fkk,Fkl\Fl,Fcl,Fkl,Fll)
> 	gen detH = det(H)
> 
> Fc, Fk, etc are calculated earlier in the program file.
> 
> However - I get an error message "Fc not found"


Stata won't allow you to insert a whole variable 
in this position, even if it only obtains one 
observation. The strange message is emitted because 
Stata is prepared to put named scalars in like 
this, but evidently you have no scalar named -Fc-.

You can specify Fc[1] or whatever to insert 
particular values for a variable. 

On the whole it seems likely that it would be much 
better style and more efficient for the upstream 
calculation to produce scalars, not variables, but 
in the absence of most of your code, that's 
a guess. 

But you _are_ putting a determinant -- one number -- 
in the new variable -detH-, and that is not 
necessary on the face of it. 

What might make sense to loop around roughly like 
this 

gen detH = . 

forval i = 1 / whatever { 

	do some stuff 
	
	form the matrix H  

	qui replace detH = det(H) in `i' 

} 

Nick 
[email protected] 
*
*   For searches and help try:
*   http://www.stata.com/support/faqs/res/findit.html
*   http://www.stata.com/support/statalist/faq
*   http://www.ats.ucla.edu/stat/stata/



© Copyright 1996–2024 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   What's new   |   Site index