Announcement

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

  • Bug in xthdidregress?

    Hello all,

    I'm playing around with the new DiD commands in Stata 18. I found this error:
    Code:
    . webuse akc
    (Fictional dog breed and AKC registration data)
    
    . xtset breed year
    
    Panel variable: breed (strongly balanced)
     Time variable: year, 2031 to 2040
             Delta: 1 unit
    
    . xthdidregress (registered best) (movie), group(breed)
    That runs without problem. But if I change the format of year to monthly, it then throws an error.
    Code:
    . format year %tm
    
    . xthdidregress twfe (registered best) (movie), group(breed)
    note: variable _did_cohort, containing cohort indicators formed by treatment variable movie and group variable
          breed, was added to the dataset.
    
    Computing ATETs using margins ...
    2129m4 invalid name
    r(198);
    I am not sure whether the error is due to margins having trouble managing date variables with a particular format, or due to xthdidregress. I figure formatted date variables should be fully supported.
    The same error is thrown with any of the estimators available in xthdidregress and with hdidregress.

  • #2
    This is a bug in the sense that the commands cannot handle your format change; but a natural question is why you would ever want to do that.

    First, an xtset in terms of year has side-effects for what Stata will do, which should be benign whenever it matches the fact, in terms of presentation in tables and graphs.

    Here year is 2031 to 2040.

    Now

    Code:
    format %tm year
    says to Stata: those numbers like 2031 to 2040 are really to be considered as months for display purposes. Let's see what that does


    Code:
    . di %tm 2031
     2129m4
    
    . di %tm 2032
     2129m5
    As a monthly date 2031 is April 2129, remembering that for Stata monthly dates are counted relative to 0 as January 1960.

    My guess is that you need to change your xtset as well as you've now given Stata information that is contradictory. There is no point in giving a date variable a different date display format unless you also change the values. It's not a major bug if commands respond in a puzzled way to contradictory input.

    For more on changing display format, and why it does less than people think, see https://journals.sagepub.com/doi/pdf...867X1201200415

    Presumably you did something similar with your real data, but the same point would apply there.
    Last edited by Nick Cox; 24 May 2023, 04:20.

    Comment


    • #3
      Thanks Nick. That example of changing the format was a way to get Stata to throw the error. I am thinking of applications in which the time variable is in months (or any other frequency smaller than a year) in a long panel. Of course, it is harmless to simply count months since the start of the sample. But as the panel gets longer, and frequency more fine, it is very handy to use the appropriate format. That convenience functionality in Stata stops being convenient when it is not supported. I think programming internals to make the command work with formatted dates should be straightforward since, as you mention, formatted dates are just makeup for numeric variables.

      Comment


      • #4
        OK, so I had another look and tested my guess. Given consistent information, the code still fails, and now I agree with you. This looks like a bug. (Naturally, the code plays no attention to the name year.)

        Code:
        . webuse akc, clear 
        (Fictional dog breed and AKC registration data)
        
        . xtset breed year
        
        Panel variable: breed (strongly balanced)
         Time variable: year, 2031 to 2040
                 Delta: 1 unit
        
        . format year %tm
        
        . xtset breed year 
        
        Panel variable: breed (strongly balanced)
         Time variable: year, 2129m4 to 2130m1
                 Delta: 1 month
        
        . xthdidregress twfe (registered best) (movie), group(breed)
        note: variable _did_cohort, containing cohort indicators formed by treatment variable movie and group variable
              breed, was added to the dataset.
        
        Computing ATETs using margins ...
        2129m4 invalid name
        r(198);

        Comment


        • #5

          Is there an official way of submitting bugs or posting here is enough for StataCorp to notice?

          Comment


          • #6
            It may be sufficient but I would advise taking this directly to Stata Technical Services.

            https://www.stata.com/support/faqs/t...-tech-support/

            Comment


            • #7
              Dear Miguel,

              Thanks for reporting this problem. We will take a closer look and will provide a fix in a future update.

              Comment


              • #8
                In the mean time
                take a look at csdid and or csdid2 (search on google). May work better in some cases than xthdidregress and I’m usually good to answer questions or problems that arise

                Comment


                • #9
                  I will check them out. Thank you.

                  Comment

                  Working...
                  X