Announcement

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

  • foreach with more global

    Dear All,

    myabe a stupid question.,,,but I cannot get ride of this.

    I have:

    Code:
    global reg1 "x1 x2 x3"
    global reg2 "x1 x2 x3 x4 x5"
    global reg3 "x1 x2 x3 x4 x5 x6 x7"
    I would like to run a regression using those three global one by one. If I type:

    Code:
    foreach r of global reg1 reg2 reg3{
    xtreg de_investment `r' i.year, fe r
    testparm i.year
    }
    I get an error message saying that { is required.

    Is it possible to run a foreach command using three or more global?

    Thanks in advance





  • #2
    The way your used the foreach command is not compatible with multiple globals. The code below should solve your problem.
    foreach r in $reg1 $reg2 $reg3 {
    your code here
    }

    Comment


    • #3
      Globals? Just say No.

      Code:
      local reg1 x1 x2 x3
      local reg2 x1 x2 x3 x4 x5
      local reg3 x1 x2 x3 x4 x5 x6 x7    
      forval r = 1/3 {    
           xtreg de_investment `reg`r'' i.year, fe r    
           testparm i.year
      }

      Comment


      • #4
        Hi Nick,

        thanks for your reply. I tried it but I get an error message saying

        1 invalid name

        Why is that?

        Comment


        • #5

          Sorted out. Thanks again Nick.

          Comment


          • #6

            Sorted out. Thanks again Nick.

            Comment

            Working...
            X