Announcement

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

  • Regressing specific years using panel data transformed from wide to long

    Hi All,

    I just transformed some wide panel data into long form panel data so that I could carry out fixed effect analysis easily.


    Before I had columns representing variables by year so e.g. profit21, profit20, profit19,......, employees21, employees20,..... and so on

    now it looks more like:
    yr profit employees debt
    17 value for 2017 data ....
    18 value for 2018 data ....
    19 value for 2019 .... data ...
    20 ..... data ....
    and so on. Sorry if this was obvious i am still fairly new to stata


    now my question is

    before I could regress:

    reg profit21 employees19 debt20 ......

    but now how can i regress combination of different years like I did when it was in wide form?

    I've been making new variables but its starting to look like wide form again which seems like a waste of time and generally wrong.

    Any help is appreciated


  • #2
    Do you mean, for example, that you only want to regress with the data for 2017-2019?
    Code:
    regress y x if inrange(yr,2017,2019)
    Or, for example, you only want to use the data for 2015, 2017, and 2019?
    Code:
    regress y x if inlist(yr,2015,2017,2019)
    For more details
    Code:
    help inrange()
    help inlist()
    its starting to look like wide form again which seems like a waste of time and generally wrong
    Agreed, wide layout is wrong for panel data. You may want to look at the Stata Longitudinal-Data/Panel-Data Reference Manual PDF included in your Stata installation and accessible from Stata's Help menu.
    Last edited by William Lisowski; 16 Jul 2022, 11:35.

    Comment


    • #3
      Sort of,

      I want to regress y for year 2021 only and then x, say, for year 2019 only and another variable say z for year 2018

      can i set specific year ranges for each individual component of the regression?

      so if it was wide form it would look like this:

      reg y_21 x_19 z_18


      Last edited by Lalo Salamanca; 16 Jul 2022, 11:41.

      Comment


      • #4
        Code:
        reg profit21 employees19 debt20 ......
        translated literally becomes
        Code:
        xtset firm yr
        reg profit L2.employees L1.debt ...... if yr==21
        where firm is the identifier for your firm and yr is your date variable.

        You should definitely review the documentation I suggested in post #2. Also
        Code:
        help tsvarlist

        Comment


        • #5
          I see thank you so much William, I will look at the pdf too!

          Comment

          Working...
          X