Announcement

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

  • xtset, gives me an error

    Hi!

    I have the following dataset:

    unit_number, Year, costs

    I would like to calculate the difference in costs for each unit, and I would to do that for different time intervals. In the dataset I have years 2005-2015. Thus, if I define yearly changes, it works:

    Code:
    xtset unit_number Year, delta(1)
    gen costs_lead=F.costs
    gen diff_costs=costs_lead - costs
    But then if I want the 3- year changes it gives me an error:

    Code:
    xtset unit_number Year, delta(3)
    gen costs_lead=F.costs
    gen diff_costs=costs_lead - costs
    The error: "time values with period less than delta() found"

    So, it is basically telling me that I can get yearly changes instead of 3-year changes. But I am interested in 3 year changes. I do not understand why this is an error and not a warning.

    Please let me know how I should fix this.

    Thanks!



  • #2
    Alex:
    what if you create a 3-year -timevar-?
    Kind regards,
    Carlo
    (Stata 19.0)

    Comment


    • #3
      Originally posted by Carlo Lazzaro View Post
      Alex:
      what if you create a 3-year -timevar-?
      I am not sure what you mean. Do you mean deleting some observations such that it does not see smaller time periods?

      But I cannot do that, because I need the following:
      if 2005 - then value from 2008 should be taken.
      if 2006 - then value from 2009 should be taken.
      ​​​​​​​if 2007 - then value from 2010 should be taken.
      ​​​​​​​if 2008 - then value from 2011 should be taken.
      ​​​​​​​if 2009 - then value from 2012 should be taken.
      ​​​​​​​if 2010 - then value from 2013 should be taken. ​​​​​​​if 2011 - then value from 2014 should be taken.
      ​​​​​​​if 2012 - then value from 2015 should be taken.
      ​​​​​​​if 2013 - then value should be missing (no year 2016)
      ​​​​​​​if 2014 - then value should be missing (no year 2017)
      ​​​​​​​if 2015 - then value should be missing (no year 2018)

      So, I need all the observations in the dataset.

      Comment


      • #4
        Code:
        xtset unit_number Year, delta(1)
        gen costs_lead3 = F3.costs
        gen diff_costs = costs_lead3 - costs

        Comment


        • #5
          Originally posted by Nick Cox View Post
          Code:
          xtset unit_number Year, delta(1)
          gen costs_lead3 = F3.costs
          gen diff_costs = costs_lead3 - costs
          It works, thank you! :-)

          Comment

          Working...
          X