Statalist


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

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


From   "Thomas Jacobs" <[email protected]>
To   [email protected]
Subject   Re: st: Re: Using a scalar/macro for loop limit in building Sureg equations
Date   Mon, 3 Nov 2008 16:43:30 -0600

Martin,

Thanks, the = sign did the trick.  (I had tried the `Count' version
which of course works with a local but not scalar - not that I knew
that before reading Maartin Buis reply.)

Tom

On Mon, Nov 3, 2008 at 4:13 PM, Martin Weiss <[email protected]> wrote:
> Use a -local- or just write
>
> forvalues i=1/`=Count'{
> ....
> }
>
> HTH
> Martin
> _______________________
> ----- Original Message ----- From: "Thomas Jacobs" <[email protected]>
> To: "StataList" <[email protected]>
> Sent: Monday, November 03, 2008 10:58 PM
> Subject: st: Using a scalar/macro for loop limit in building Sureg equations
>
>
>> 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/
>>
>
>
> *
> *   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/
>



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



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