Announcement

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

  • regression with multiple explanatory variables stored in one variable in long format

    I have panel data, as constructed below for illustration. I wonder if there is a way to perform regression on the panel data so that each panel can serve as an explanatory variable for others? I am now doing it by reshaping the data but wonder if there is a better way. Thanks in advance for your advice.

    Code:
     clear *
    set obs 100
    gen panel=1
    gen day=_n
    gen x=runiform(1,100)
    
    set obs 10000
    replace panel=panel[_n-100]+1 if panel==.
    replace day=day[_n-100] if day==.
    replace x=x[_n-100] if x==.
    
    xtset panel day
    
    gen y=runiform(1,10)
    
    reshape wide y , i(day x) j(panel)
    regress y1 x y2-y100 //is it possible to do regression on the original panel data to achieve this?

  • #2
    In your example your first value of y is influenced by all future values of y. How can the future influence the past?

    If you want the past to influence the future in a panel model, then my first suggestion would be to look at the residuals() option in mixed. This will allow you to include a time structure at the lowest level.
    ---------------------------------
    Maarten L. Buis
    University of Konstanz
    Department of history and sociology
    box 40
    78457 Konstanz
    Germany
    http://www.maartenbuis.nl
    ---------------------------------

    Comment


    • #3
      Hi Charlie,

      This looks like an interesting problem. Do you want to run the regression only for 1 panel (using y2-y100 as indep var), or do you want to use for each panel, the y of all other 99 panels as indepvar?

      Comment


      • #4
        Maarten Buis hi Maarten, thanks for your reply. i m not sure if i follow you. in my reshaped data, i should be regressing y1 on concurrent x and other y's.

        ashish tyagi ideally i can choose which panels to include as indepvar.

        Comment


        • #5
          You have a variable called day, suggesting time. So I assume from your example that you have multiple observations at different times of the same individual/company/cow/whatever_your_unit_is. I also assumed that larger values on day represent later observations. So as a consequence, if you reshape your data y1 will be the first observation of y, y2 the second, and so on. So if you do reg y1 x y2 y3 ..., that means that the first observation of y is influenced by the second observation of y, i.e. the future predicts the past rather than the other way around.

          Part of the problem is that, because you abstracted from your real problem, I need to make a lot of assumptions of what your problem may be. So if this explanation does not work for you, maybe we can fix it by you telling us about your real problem: i.e. your real research question, real variables, real datastructure.
          ---------------------------------
          Maarten L. Buis
          University of Konstanz
          Department of history and sociology
          box 40
          78457 Konstanz
          Germany
          http://www.maartenbuis.nl
          ---------------------------------

          Comment


          • #6
            Thanks for the reply again Maarten. I am not sure if i did the reshape the way i intended. after reshaping, y1 should correspond to panel 1, and y2 panel 2...(there are 100 panels in my example). there are also 100 days in my example (maybe that caused the confusion). In any case, i intend to regress y from one panel on y from other panels.

            Comment


            • #7
              I see what you mean, and you did the reshape correct.

              One alternative way of modeling this you can consider is crossed random effects, see e.g. example 10 in the manual entry for mixed.
              ---------------------------------
              Maarten L. Buis
              University of Konstanz
              Department of history and sociology
              box 40
              78457 Konstanz
              Germany
              http://www.maartenbuis.nl
              ---------------------------------

              Comment


              • #8
                Originally posted by charlie wong View Post
                Thanks for the reply again Maarten. I am not sure if i did the reshape the way i intended. after reshaping, y1 should correspond to panel 1, and y2 panel 2...(there are 100 panels in my example). there are also 100 days in my example (maybe that caused the confusion). In any case, i intend to regress y from one panel on y from other panels.
                Your reshape is indeed correct.

                Comment

                Working...
                X