Announcement

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

  • Treating negative integer values in a "ym" date variable

    Hello,

    I am trying to run a Diif-in-Diff analysis and I ran the following code, but I keep receiving an error due to the format of my date variable:

    ```
    didregress (log_price) (DiD), group(city) time(year_month)
    ```
    where my Y variable is log price, and DiD refers to treatment (i.e. 1 for treatment and 0 otherwise), city is the level at which I am clustering my observations, and then time is at the monthly level.
    Here is the dataex:

    ```
    * Example generated by -dataex-. For more info, type help dataex
    clear
    input float(log_price DiD) str21 city_trans float year_month
    6.35437 0 "Santa Barbara" -6360
    6.352306 0 "Santa Barbara" -6359
    6.317792 0 "Santa Barbara" -6358
    6.32594 0 "Santa Monica" -6357
    6.307189 0 "Santa Monica" -6356
    6.404986 0 "Santa Monica" -6355
    6.417549 0 "Santa Monica" -6354
    ```

    What's confusing to me as a new Stata user is that when I check the data browser, the year and month under the date variable read correctly to the human eye, but in Stata, such values are read as negative integers.

  • #2
    Read all about it at https://en.wikipedia.org/wiki/System_time. You can of course create your own time variable that starts from zero or one:

    Code:
    qui sum year_month
    gen new_timevar= year_month- r(min)
    Last edited by Andrew Musau; 14 Feb 2022, 11:50.

    Comment


    • #3
      Negative integers for Stata monthly dates mean dates on or before December 1959, which should not be troubling if that is a date in your dataset.

      But, but, but: What is year_month precisely? An interpretation that it is a Stata monthly date

      Code:
      . di %tm -6360
       1430m1
      implies that you have price data for Santa Barbara in January 1430, which seems a real stretch to me.

      Is it a daily date? Or something else?

      Code:
      . di %td -6360
      03aug1942

      Comment


      • #4
        Originally posted by Nick Cox View Post
        Negative integers for Stata monthly dates mean dates on or before December 1959, which should not be troubling if that is a date in your dataset.

        But, but, but: What is year_month precisely? An interpretation that it is a Stata monthly date

        Code:
        . di %tm -6360
        1430m1
        implies that you have price data for Santa Barbara in January 1430, which seems a real stretch to me.

        Is it a daily date? Or something else?

        Code:
        . di %td -6360
        03aug1942
        Thanks Cox!
        On the date variable, the dataset is based on Southern California cities but using Islamic calendar or a Hijri calendar system. For instance, the year 1430 and month 1 refer to Dec 2008, year 1430 and month 2 refer to Jan 2009, etc.

        Comment


        • #5
          Unfortunately Stata has a very specific idea of Stata Internal Format dates and times that are used in its calculations, and they are based on the Gregorian calendar, so you will need to find a way to express your Hijri dates as Gregorian dates in order to use them to create Stata Internal Format dates for use in Stata.

          Stata's "date and time" variables are complicated and there is a lot to learn. If you have not already read the very detailed Chapter 24 (Working with dates and times) of the Stata User's Guide PDF, do so now. If you have, it's time for a refresher. After that, the help datetime documentation will usually be enough to point the way. You can't remember everything; even the most experienced users end up referring to the help datetime documentation or back to the manual for details. But at least you will get a good understanding of the basics and the underlying principles. An investment of time that will be amply repaid.

          All Stata manuals are included as PDFs in the Stata installation and are accessible from within Stata - for example, through the PDF Documentation section of Stata's Help menu.

          Comment


          • #6
            Originally posted by William Lisowski View Post
            Unfortunately Stata has a very specific idea of Stata Internal Format dates and times that are used in its calculations, and they are based on the Gregorian calendar, so you will need to find a way to express your Hijri dates as Gregorian dates in order to use them to create Stata Internal Format dates for use in Stata.

            Stata's "date and time" variables are complicated and there is a lot to learn. If you have not already read the very detailed Chapter 24 (Working with dates and times) of the Stata User's Guide PDF, do so now. If you have, it's time for a refresher. After that, the help datetime documentation will usually be enough to point the way. You can't remember everything; even the most experienced users end up referring to the help datetime documentation or back to the manual for details. But at least you will get a good understanding of the basics and the underlying principles. An investment of time that will be amply repaid.

            All Stata manuals are included as PDFs in the Stata installation and are accessible from within Stata - for example, through the PDF Documentation section of Stata's Help menu.
            Thanks a lot, this is really helpful!

            Comment

            Working...
            X