Announcement

Collapse
No announcement yet.
X
  • Filter
  • Time
  • Show
Clear All
new posts

  • dfactor in a for loop with changing number of factors

    Hi,
    is there a way to write a loop where the number of factors changes in each step? Something like
    Code:
    forv k=1/3{
    dfactor (X Y Z =, noconstant) (f(1/`k')=, ar(1/3))
    }
    which of course doesn't work because "f(1/3) contains at least one invalid name". The point is that it seems you need to specify names for fators, eg f1 f2 if you want two, or f1 f2 f3 if you want three. You can't call dfactor with the number of factors. Notice that for autoregressive part you can: ar(1/3) is enough, you don't need to specify smth like a1 a2 a3...

  • #2
    Your question is not clear, but maybe the following helps where you will be adjusting the highlighted:

    Code:
    local factors
    forv k=1/3{
        local factors `factors' f`k'
        if `k'==3{
            dfactor (X Y Z =, noconstant) (`factors'=, ar(1/3))
        }
    }

    Comment


    • #3
      Hi Andrew,

      thank you for your quick answer. Sorry for not being clear, what I wanted to obtain was the following:
      Code:
      dfactor (X Y Z =, noconstant) (f1=, ar(1/3))
      dfactor (X Y Z =, noconstant) (f1 f2=, ar(1/3))
      dfactor (X Y Z =, noconstant) (f1 f2 f3=, ar(1/3))
      So I modified your solution, and now it does the job:
      Code:
      local factors
      forv k=1/3{
          local factors `factors' f`k'
          dfactor (X Y Z =, noconstant) (`factors'=, ar(1/3))
      }
      In the meantime, I did in the end manage to get a working loop, which for the record I paste below:
      Code:
      foreach F in "f1" "f1 f2" "f1 f2 f3"{
          dfactor (X Y Z =, noconstant) (`F'=, ar(1/3))
      }
      I must admit I still struggle with locals, scalars, " "-s, ` '-s etc. Thank you again for your guidance.

      Comment

      Working...
      X