Announcement

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

  • Create a loop for regressions

    Good morning everybody,

    I have a dataset with 150 variables and I would like to create a loop to perform a regression for each of the variables on themselves lagged one period. Something like this for all the variables in my dataset:

    Xt=a+B*Xt-1

    I would also like to do the same for calculating the ADF test for all the variables in the dataset with the dfuller or dfgls command.

    I know that I have to deal with the foreach o forevalues commands but I am not able to do it and it would save me a lot of time.

    Thanks in advance

  • #2
    Panel data or single time series? Please show us the regression command you would use in a particular case.

    Comment


    • #3
      Sorry for not being clear about that. I mean single time series using the reg command. I have already tsset my data. For instance, for one of my particular variables the regression command would be:

      . reg unemployment l.unemployment


      Thanks for your consideration

      Comment


      • #4

        Code:
        foreach v of var frog toad newt {
               di "{title:`v'}
               regress `v' L.`v'
               di
        }
        See also
        Code:
        help varlist
        for wildcard methods to give variable lists concisely.
        Last edited by Nick Cox; 22 Jan 2020, 05:03.

        Comment


        • #5
          Thank you very much for your help Nick. It works perfectly!!!

          Comment

          Working...
          X