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

RE: st: calling the value of a scalar into a variable


From   Ernest Berkhout <[email protected]>
To   [email protected]
Subject   RE: st: calling the value of a scalar into a variable
Date   Mon, 06 Oct 2003 16:16:46 +0200

At 15:48 6-10-2003, Dev Vencappa wrote me privately:
thanks a lot for your tip to this problem. I have implemented it for variable netpremmean and it works fine. Now suppose I have four variables in total, why does it not work? I am copying my loop file below. COuld you spot the mistake please?
Also, if I have to do it for 20 different series for each of these variables for each lag length from 1 to 6, could you give a suggestion how this can be shortened within a loop please?

local z "netpremmean disclmmean elrmean solvmean"
foreach k of local z{
postfile myhandle lags aic`k' sic'k' using "c:\unitroot\unitrootlagselection`k'", replace
forvalues x = 1/6 {
regress D.`k' L.`k' L`x'D.`k'
matrix b`x'=get(_b)
scalar AIC`k'`x'=log(_result(4)/_result(1))+(colsof(b`x')/_result(1))*2
scalar SIC'k'`x'=log(_result(4)/_result(1))+(colsof(b`x')/_result(1))*log(_result(1))
post myhandle (`x') (AIC`k'`x') (SIC`k'`x')
}
postclose myhandle
}

The error message I am getting is invalid name. can't spot where the mistake is.
Better ask all your questions directly to Statalist. Firstly, a lot more people will be able to give you the answer. Secondly, a lot more people are interested in the discussion, so they profit from your question and the answers as well. Third, an maybe most important in this particular case: I myself only just learned this trick today in the Stata NetCourse, so you better have Nick or someone else to read it too... :-)

One common remark: to see where exactly a program or loop gives an error, try "set trace on" and you might have some more information which makes debugging more easy.

In this particular problem, I suspect that the name "myhandle" in the 3rd line can be used only once, so it creates an "invalid name" when the loop has its second run. One can get around that by substituting " myhandle`x'`z' " (without double quotes) I think.


Ernest Berkhout
Stichting voor Economisch Onderzoek
Universiteit van Amsterdam

Kamer 3.08
Roetersstraat 29
1018 WB Amsterdam

tel.:+ 31 20 525 1630
fax:+ 31 20 525 1686
http://www.seo.nl
=================================
"To an economist, real life is a special case"
=================================

*
* 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