Announcement

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

  • TWFE/Difference-in-Difference

    Hi, first time posting in statalist. I am trying out work out a model to estimate the impact of smart meters on energy consumption levels (billed units). The policy implementation began in 2020 in India, and every year increasing no. of consumers were smart metered. It is a panel data where smart meter penetration increased from 3% in 2020 to 95% in 2025. The unit of observation is the consumer, and each row corresponds to a month-year, covering the period from April 2019 to March 2025. I understand the theory but haven't applied DiD ever in my work, hence the post.

    I create a dummy variable which takes the value 0 for all months before smart meter installation for a consumer and 1 for all post smart metering months. i am applying individual fixed effect so this is a within consumer comparison of billed units. I understand that staggered DiD is well suited for this kind of data, which I am finding a bit convoluted currently. So i am running a two way Fixed Effects model.

    The command looks some thing like this:

    areg billed_units i.bill_month i.fin_year i.sm, absorb(consumer_id), cluster(consumer_id).


    bill_month and fin_year are time fixed effects. i.bill_month controls for seasonality (Eg. billed units are higher in June, not just because of smart meter installation in May but also because June is on average the hottest month of the year). i.fin_year is the year fixed effect to control for Tariff changes or energy efficiency changes over the years.

    Is my basic setup correct? Some research tells me that conducting an event study will also help here to basically gauge to trend of billed units. (Due to immediate correction they can be higher but over time, may be due to behavioural changes they reduce compared to pre smart metering). Any suggestions on how to better the regression is welcome.

    To check for parallel trends assumption, at the preliminary level i want to check for pre smart metering trends in billed units of the non-smart metered and now smart metered groups.
    In essence, as I understand, the average billed units levels can be different but they should not diverge over time.

    Thanks, this work is a policy level analysis of the impact (not for an academic paper) so I am trying to keep the model basic while trying to optimize on causality, if that makes sense.



  • #2
    I agree with most of what you have done. But I would not represent time with separate month (1-12) and year variables. The problem is that by doing that, you are imposing constraints on the values of the fixed effects in different months(1/year1-12/yearN). For example, with the separate month and year representation, the difference in the "net" fixed effect of January 2020 and June 2020 must be exactly the same as the difference in the "net" fixed effect of January 2021 and June 2021, because both of those differences are exactly equal to the difference between the January and June fixed effects. So, unless you have reason to believe that this constraint actually describes reality (I have no expertise in energy consumption patterns, but from a common sense perspective it would astonish me if this were true) you are mis-specifying the effects of time. That mis-specification will corrupt the estimation of the i.sm effect, which is your key result.

    So I would
    Code:
    gen month_year = ym(fin_year, bill_month)
    format month_year %tm
    areg billed_units i.sm, absorb(consumer_id month_year), cluster(consumer_id)

    By the way, if you are using the current version of Stata, you don't have to specify the the month_year effect in the varlist: you can put it in the -absorb()- option and avoid having the output cluttered up with month_year effects that, while necessary for correct estimation of the i.sm effect, are of no inherent interest.

    By using the single month_year variable, you will get independent estimates of the shocks associated with each month of each year. You will not be able to directly estimate the seasonal effects in this model, but they are indirectly captured by the variation in the estimates of the i.month_year coefficients. In other words, the seasonal effects are adjusted ("controlled") for, but not directly estimated. And that is what matters.

    Comment


    • #3
      Konica:
      welcome to this forum.
      As an aside to Clyde's helpful advice, why not relying on -xtdidregress-?
      In assition, the community-contributed -csdid- "implements Callaway and Sant'Anna (2020) estimator for DID
      models with multiple time periods. " (quoted from -csdid- helpfile).
      Just type -search csdid- from within Stata to spot it and download it.
      Last edited by Carlo Lazzaro; 10 Jan 2026, 11:55.
      Kind regards,
      Carlo
      (Stata 19.0)

      Comment


      • #4
        Hi Clyde, Thanks for the reply. That is a brilliant point. Your explanation really helps. I had not thought about it. Also, will follow your tip of including fixed effects in the absorb function.

        Comment


        • #5
          Hey Carlo, Thanks for the reference. I didnot know about the xtdidregress. Yes, I am aware of csdid. I am currently reading their paper and understanding the methodology. The goal is to move to csdid for the analysis once I am confident with my theoretical understanding of their work.

          ThankYou !!!

          Comment


          • #6
            Konica:
            you might be interested in the following paper: https://www.linkedin.com/posts/valen...15942656-O8TH/
            Kind regards,
            Carlo
            (Stata 19.0)

            Comment

            Working...
            X