How do I append an equation to a group in a loop?

Use this forum to post questions about syntax problems or general programming issues. Questions on implementing a particular aspect of econometrics should go in "Econometrics Issues" below.
macro
Posts: 70
Joined: Thu Jul 16, 2015 3:01 pm

How do I append an equation to a group in a loop?

Unread post by macro »

For example, in this code:

Code: Select all

dofor s = gdp cons gce gov
    linreg(define = eq) s
    # unemp{1 to 4}
    
    group my_model eq>>s
end dofor s

display %modelsize(my_model)
the result is a model with only one equation, because the model is overwritten by each group statement in the loop. How do I append equations to a model, in a loop or otherwise?
TomDoan
Posts: 7814
Joined: Wed Nov 01, 2006 4:36 pm

Re: How do I append an equation to a group in a loop?

Unread post by TomDoan »

You can use model=model+equation

Code: Select all

declare model my_model
dofor s = gdp cons gce gov
    linreg(define = eq) s
    # unemp{1 to 4}
    compute my_model=my_model+eq
end dofor s
macro
Posts: 70
Joined: Thu Jul 16, 2015 3:01 pm

Re: How do I append an equation to a group in a loop?

Unread post by macro »

Perfect! And it supports any variable with the model type, even items from a hash[model] aggregator. Thank you!
Post Reply