Announcement

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

  • Running a multiple regressions at once

    Hi all,

    I'm new into Stata and I'm struggling with running a multiple of regressions automotically. I need to run a number of following regressions on panel data, that would basically look like:

    xtreg spot x1
    xtreg spot x2
    xtreg spot x3
    xtreg spot x4 etc.

    My current commands look like following, however its not working...

    foreach v of varlist LogIndustriallagged1380-LogIndustriallagged1800 {
    xtreg Spot v
    }

    Or maybe the idea itself is wrong and I should use different command? I would appreciate your help.

    Regards,
    Agata

  • #2
    You have to refer to the local macro implied with appropriate punctuation, as otherwise v means a variable with that name (or if abbreviation is allowed) a variable whose name can be so abbreviated without ambiguity.

    Code:
    xtreg Spot  `v'
    Check whether you mean spot or Spot as different spellings imply different variables.
    Last edited by Nick Cox; 17 Feb 2018, 07:55.

    Comment


    • #3
      `v' was the mistake Thank you so much for your help!

      Comment


      • #4
        Is it now somehow possible to export outcomes of all regressions into one excel file? When i use outreg2 command, it gives me only the data only on the very last regression, not all of them as I need.

        ssc install outreg2
        outreg2 using filefinal, replace excel

        Regards,
        Agata

        Comment


        • #5
          I don't use outreg2 ever, but someone else may be able to help.

          Comment


          • #6
            I will suggest you to use putexcel code.

            Comment


            • #7
              Hi, Agata: Please have a look of the following code
              Code:
              sysuse auto, clear
              
              local replace replace
              foreach v of varlist mpg rep78 length {
                reg price `v'
                outreg2 using "out", word excel dec(3) ctitle(`v') `replace'
                local replace append
              }
              Ho-Chuan (River) Huang
              Stata 16.0, MP(4)

              Comment

              Working...
              X