Announcement

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

  • Regression with Fixed Effects - Repeated Time Values

    Dear Statalist Users,

    I am not really familiar with Stata, I use it to write my dissertation at this moment. I am working with Stata 14. My dataset is quite large ~ 400.000 observations; and I want to to a regression with fixed effects.

    I understand that the first command is letting Stata know that there is Panel Data, with the following syntax:
    xtset panelvar timevar

    However, if i do this with my variables I get the following error:

    repeated time values within panel
    r(451);

    I know that I have repeated time values; because I have different weeks and years in my dataset. But I don't know how to fix this because the weeks and years are unique identifiers of my data set. This is what my data set looks like:

    Product_Number - Product - Week - Year - Retailer - Variable_X - Lag_Variable_X

    1234 | product 1 |week 13 |2018 |retailer x | 0.2 | .
    1234 | product 1 |week 13 |2018 |retailer y | 0.3 | 0.2
    1234 | product 1 |week 13 |2018 |retailer z | 0.4 | 0.3
    1234 | product 1 |week 13 |2019 |retailer x | 0 |
    1234 | product 1 |week 13 |2019 |retailer y | 0.3 |
    4567 | product 2 |week 13 |2018 |retailer z | 0.4 |
    4567 | product 2 |week 13 |2019 |retailer x | 0.5 | .
    4567 | product 2 |week 13 |2019 |retailer z | 0.2 | 0.5
    ...
    5678 | product 3 |week 52 |2019 |retailer x | 0.3 |
    etc.

    What steps did I take for the Xtset?

    1. egen time = group (year week)
    2. sort product_number week
    3. by product_number: gen lag_variable_x = variable_x[n-1] - I think the lag is not relevant in this problem

    So for the xtset command I used product_number as panelvar and time als timevar.
    -> xtset product_number time

    I hope I explained it clearly. What did I do wrong?

  • #2
    Amber:
    welcome to this forum.
    The usual fix is to -xtset- your dataset with -paneild- only.
    Unfortunately, this fix will not allow you to use time-series related commands (see -help tsvarlist-).
    Kind regards,
    Carlo
    (Stata 19.0)

    Comment


    • #3
      Originally posted by Carlo Lazzaro View Post
      Amber:
      welcome to this forum.
      The usual fix is to -xtset- your dataset with -paneild- only.
      Unfortunately, this fix will not allow you to use time-series related commands (see -help tsvarlist-).
      Thanks for your answer Carlo, I tried this in Stata and the error is gone. However, I would like to include the time series in the dataset. Do you know a manner how I can fix my time series so I can xtset with an id and time series?

      Comment


      • #4
        Amber:
        the only way is to create a new -timewar- that can work around the previous repeated time values within panel error.
        As usual -egen- can provide some ideas.
        Kind regards,
        Carlo
        (Stata 19.0)

        Comment


        • #5
          To add to Carlos helpful suggestions, it seems as if you have multiple observations for the given product in a given week in a given year because you have multiple retailers. One way to do this would be to make the panel the product–retailer. Then I suspect your year and week identifiers would work for time. You can't really have time set and do leads and lags if you have multiple observations for a given panel/time. That is, if you tried to lead or lag in the data you present you would really want to be leading and lagging for product/week/year/retailer. Otherwise, you would be leading and lagging between retailer X and retailer y which makes no sense

          Comment

          Working...
          X