[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

st: Using a scalar/macro for loop limit in building Sureg equations

From   "Thomas Jacobs" <>
To   StataList <>
Subject   st: Using a scalar/macro for loop limit in building Sureg equations
Date   Mon, 3 Nov 2008 15:58:57 -0600

I am trying to build a more flexible do file process in working with a
varying number of firms for which I wish to estimate seemingly
unrelated regressions with sureg.  The code I have now is

*sureg drop all unnecessary variables
keep TradeDateNum CompanyNum LnRt*

egen Companies=group(CompanyNum)

reshape wide CompanyNum  LnRtStock LnRtFiveYrMid, i(TradeDateNum) j(Companies)

tsset TradeDateNum

forvalues i=1/54{
	local eqn "`eqn' (LnRtFiveYrMid`i' L(1/2).LnRtFiveYrMid`i'
L(0/4).LnRtCDX LnRtCMT LnRtTED L(0/2).LnRtStock`i') "

sureg `eqn',corr

CompanyNum is a label matched list of companies which will vary with
the time line examined so I cannot use CompanyNum as a loop descriptor
since it will not be contiguous.  Thus I create the Companies variable
which is contiguous via the group command.  However, I have been
unable to figure out how to use either a scalar or local macro with
the maximum value of Companies for implementing the loop.  Right now I
have the current number of firms, 54, hardcoded.  For instance I have

summ Companies
scalar Count = r(max)

but I keep getting errors when I try to substitute Count into my
forvalues statement:

. forvalues i=1/Count{
  2.         local eqn "`eqn' (LnRtFiveYrMid`i'
L(1/2).LnRtFiveYrMid`i' L(0/4).LnRtCDX LnRtC
> MT LnRtTED L(0/2).LnRtStock`i') "
  3. }
invalid syntax

Can someone suggest how best to do this?  Thanks.

Thomas Jacobs
*   For searches and help try:

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