Announcement

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

  • Record-to-date value in a time series or panel

    I will illustrate my question with an example.

    Say I have a variable called Temperature for 100 years in a country X.

    I would like to create a variable Temperature_Record such that for year n Temperature_Record=max(Temperature(year 1:year n))

    That is I want it to record the maximum temperature reached as of year n. This will give me a variable that will only increase over time naturally.

    In addition I would like to do that in a panel of countries if possible.

    Thoughts very much appreciated. I am new to STATA.

    Thank you


  • #2
    Code:
    xtset country year
    by country (year): gen wanted = temperature if _n == 1
    by country (year): replace wanted = max(L1.wanted, temperature) if _n > 1

    Comment


    • #3
      Code:
      rangestat (max) temperature, int(year . 0) by(country)
      is another way to do it using rangestat from SSC.

      See also FAQ https://www.stata.com/support/faqs/d...m-of-sequence/

      Comment


      • #4
        Thank you so much.

        Comment

        Working...
        X