Announcement

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

  • Leads and lags in a DID: "time variable not set" error

    Hi everyone,

    I am trying to run a DID where I have an interaction variable that I would like to see leads and lags for. My data is monthly, so I was thinking I could look back 6 months forwards and backwards for my regression. I am being faced with the error that "time variable not set," when I use my interaction variable "post_softdrinks" which I created using this code:

    Code:
    gen post_softdrink = (prod =="Softdrinks") * (td_combined_date>=td(01mar2016)) //interaction var w/soft drinks after the change in the tax
    I added this code into my regression, but that is what was giving me the error:

    Code:
     L(-5/5).post_softdrinks
    Pasted below is an output of my data, and also the regression that I am looking to run. Thank you in advance for any and all suggestions or tips!



    Code:
    reg rel_px ib30.id_new _Icombined_* L(-5/5).new_post_softdrink if country=="UK" & test_include_prod==1 & year>=2015 , robust


    Code:
    * Example generated by -dataex-. To install: ssc install dataex
    clear
    input str21 prod float td_combined_date str7 country float(rel_px post_softdrink)
    "Electricitygasandot"   19724 "UK"      1.0753354 0
    "Sugar"                 19724 "Ireland" 1.0343435 0
    "Food"                  19724 "UK"      1.0653728 0
    "Chocolate"             19724 "Ireland" 1.0214777 0
    "Confectioneryproducts" 19724 "Ireland" 1.0496109 0
    "Footwear"              19724 "Ireland"  .9747818 0
    "Meat"                  19724 "Ireland" 1.0602767 0
    "Fruit"                 19724 "Ireland" 1.0621866 0
    "Edibleicesandicecre"   19724 "UK"              . 0
    "Floursandothercereal"  19724 "Ireland" 1.0117648 0
    "Tea"                   19724 "Ireland"  .9939699 0
    "Yoghurt"               19724 "Ireland"  1.018664 0
    "Confectioneryproducts" 19724 "UK"              . 0
    "Footwear"              19724 "UK"       .9770688 0
    "Coffee"                19724 "Ireland" 1.0166975 0
    "Fish"                  19724 "Ireland" 1.0341365 0
    "Mineralorspringwater"  19724 "UK"              . 0
    "Freshwholemilk"        19724 "Ireland" 1.0208126 0
    "Tobacco"               19724 "Ireland"  .9005347 0
    "Eggs"                  19724 "UK"              . 0
    "Tobacco"               19724 "UK"       .8888889 0
    "Food"                  19724 "Ireland" 1.0420744 0
    "Rice"                  19724 "UK"              . 0
    "Breadandcereals"       19724 "UK"       1.041456 0
    "Milkcheeseandeggs"     19724 "Ireland" 1.0206084 0
    "Crisps"                19724 "UK"              . 0
    "Mineralwaterssoftdr"   19724 "UK"      1.0090271 0
    "Freshwholemilk"        19724 "UK"              . 0
    "Fruit"                 19724 "UK"       .9902344 0
    "Freshlowfatmilk"       19724 "UK"              . 0
    "Housingwaterelectri"   19724 "Ireland"  .9859013 0
    "Fish"                  19724 "UK"      1.0695021 0
    "Sugar"                 19724 "UK"              . 0
    "Sugarjamhoneychoc"     19724 "Ireland" 1.0362117 0
    "Mineralwaterssoftdr"   19724 "Ireland"         1 0
    "Fruitandvegetablejui"  19724 "Ireland"  .9882237 0
    "Yoghurt"               19724 "UK"              . 0
    "Coffeeteaandcocoa"     19724 "Ireland" 1.0019418 0
    "Eggs"                  19724 "Ireland" 1.0430107 0
    "Jamsmarmaladesandho"   19724 "UK"              . 0
    "Milkcheeseandeggs"     19724 "UK"      1.0894141 0
    "Coffee"                19724 "UK"              . 0
    "Vegetables"            19724 "Ireland" 1.0360624 0
    "Mineralorspringwater"  19724 "Ireland" 1.0270813 0
    "Bread"                 19724 "Ireland"     1.056 0
    "Softdrinks"            19724 "Ireland"         1 0
    "Cocoaandpowderedchoc"  19724 "Ireland"  .9790276 0
    "Freshlowfatmilk"       19724 "Ireland" 1.0119402 0
    "Jamsmarmaladesandho"   19724 "Ireland"  .9854369 0
    "Cocoaandpowderedchoc"  19724 "UK"              . 0
    "Rice"                  19724 "Ireland"  .9836364 0
    "Coffeeteaandcocoa"     19724 "UK"          1.035 0
    "Fruitandvegetablejui"  19724 "UK"              . 0
    "Softdrinks"            19724 "UK"              . 0
    "Electricitygasandot"   19724 "Ireland" 1.1135902 0
    "Chocolate"             19724 "UK"              . 0
    "Crisps"                19724 "Ireland" 1.0491159 0
    "Sugarjamhoneychoc"     19724 "UK"      1.0389345 0
    "Meat"                  19724 "UK"      1.0703206 0
    "Floursandothercereal"  19724 "UK"              . 0
    "Housingwaterelectri"   19724 "UK"         .98999 0
    "Allitems"              19724 "Ireland"      .997 0
    "Edibleicesandicecre"   19724 "Ireland" 1.0924288 0
    "Tea"                   19724 "UK"              . 0
    "Breadandcereals"       19724 "Ireland" 1.0509305 0
    "Vegetables"            19724 "UK"      1.1340206 0
    "Allitems"              19724 "UK"        .988024 0
    "Bread"                 19724 "UK"              . 0
    "Confectioneryproducts" 19755 "UK"              . 0
    "Electricitygasandot"   19755 "Ireland" 1.1146045 0
    "Meat"                  19755 "UK"      1.0775595 0
    "Coffeeteaandcocoa"     19755 "Ireland" 1.0320388 0
    "Coffeeteaandcocoa"     19755 "UK"          1.025 0
    "Fruit"                 19755 "UK"       .9736328 0
    "Vegetables"            19755 "Ireland" 1.0185186 0
    "Tobacco"               19755 "Ireland"  .9005347 0
    "Mineralorspringwater"  19755 "UK"              . 0
    "Chocolate"             19755 "UK"              . 0
    "Crisps"                19755 "Ireland" 1.0658153 0
    "Mineralwaterssoftdr"   19755 "UK"      1.0351053 0
    "Freshwholemilk"        19755 "UK"              . 0
    "Sugarjamhoneychoc"     19755 "UK"      1.0379099 0
    "Breadandcereals"       19755 "UK"       1.057634 0
    "Floursandothercereal"  19755 "UK"              . 0
    "Freshwholemilk"        19755 "Ireland" 1.0188305 0
    "Eggs"                  19755 "UK"              . 0
    "Electricitygasandot"   19755 "UK"      1.0773994 0
    "Tobacco"               19755 "UK"       .8898636 0
    "Chocolate"             19755 "Ireland"   .975945 0
    "Milkcheeseandeggs"     19755 "UK"      1.0935252 0
    "Mineralwaterssoftdr"   19755 "Ireland" 1.0350379 0
    "Tea"                   19755 "Ireland" 1.0211055 0
    "Sugar"                 19755 "UK"              . 0
    "Housingwaterelectri"   19755 "Ireland"  .9899295 0
    "Yoghurt"               19755 "Ireland" 1.0196463 0
    "Sugar"                 19755 "Ireland" 1.0414141 0
    "Confectioneryproducts" 19755 "Ireland" 1.0321012 0
    "Floursandothercereal"  19755 "Ireland"  1.017647 0
    "Fruitandvegetablejui"  19755 "UK"              . 0
    "Allitems"              19755 "Ireland"     1.002 0
    end
    format %d td_combined_date

  • #2
    Code:
    help tsset

    Comment


    • #3
      Dear Jim, Please try the following code (and note that your data is "monthly"):
      Code:
      sort country td_combined_date prod
      gen ym = mofd(td_combined_date)
      format ym %tm
      egen id = group(country prod)
      xtset id ym
      Ho-Chuan (River) Huang
      Stata 19.0, MP(4)

      Comment


      • #4
        Thank you so much, River! That worked perfectly.

        I have one more question as well: right now, the "delta" that it is counting by is per month, but is there a way to create leads and lags for multi-month intervals (3 months for example)? My data has some variation between months, but I am more interested in the general pre and post-trends rather than the individual month specifically. Do you have a any suggestions for how I could make 3 month lead and lag values (or some other number of months that I set/determine)? So to clarify, when the output displays: "F1." "F2." etc, "F1." would be the lead for the 3 month averaged price value leading up to the treatment date in the DID, and "F2." would be for months 4-6 prior to the treatment, etc.

        Thank you again for all the help you've given me so far.

        Best,
        Chris

        Comment

        Working...
        X