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
*BEGIN HERE
*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
*END HERE
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
tried:
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.
Tom
--
Thomas Jacobs
*
*   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/