Announcement

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

  • Generating continuous standardized lagged treatment variables

    I want to create several standardized continious lagged treatment variables to capture the effect of a 1 std dedication rise in windspeed on some outcome variable across time.

    I try using the following loops but they do not yield a desirable result. The logic of the variable is such that

    Min1 = Standardized_Windspeed_t-1 if Windspeed > 25 & < 49

    Here's my code:

    forvalues i = 1/15 {
    gen Hurr_Surface`i' = L`i'.vmax_sust
    replace Hurr_Surface`i' = 0 if Hurr_Surface`i' == .
    }

    forvalues i=1/15 {
    gen Min`i' = L`i'.vmax_sust_std
    replace Min`i' = 0 if L`i'.vmax_sust >49
    replace Min`i' = 0 if L`i'.vmax_sust <25
    }


    clear
    input double fips float year double vmax_sust
    48391 2018 1.021098356869877
    48007 2018 1.051862443578414
    28045 2006 4.177628671698029
    17185 1991 1.1213154480621899
    48079 2003 4.112183178927228
    36105 1991 14.10644492184711
    5143 2016 .9982955127059487
    6065 2017 0
    26127 2017 3.093376095188955
    36033 1998 1.8373491224870746
    48333 2002 6.482656141668468
    1099 1991 1.5885547838918195
    29085 2012 8.976045852622367
    20085 2013 .6892486864390626
    47101 1997 5.394388300439134
    50025 1993 4.7125097522374215
    1001 2006 5.21891364262652
    29221 1993 .6352872961542773
    31031 1998 0
    16087 2003 0
    47167 2001 4.683423502591283
    27121 1998 0
    5089 2011 2.3104643784480405
    51057 1995 6.4430845443913585
    51195 2009 1.6710968720531667
    24015 2013 9.016256362216383
    50011 1991 11.344132960404089
    25023 1997 14.111328418019523
    27097 2005 0
    13011 2001 6.911407272677595
    40053 2003 2.28343378715065
    35049 2001 0
    27055 1996 0
    8081 2011 0
    13219 2013 6.547791599929222
    47153 2016 4.228363185471687
    39041 2009 .8031827844860548
    48261 2013 2.3117117494457022
    13249 2013 7.6183572833989155
    1041 2006 6.830450960580387
    27161 2000 0
    29213 2003 2.773515846382738
    13253 1994 20.777136584433773
    13089 2013 5.248532381718499
    45075 1999 13.938524549094408
    53065 2001 0
    31159 1993 0
    13075 1997 6.382380595443415
    41071 2014 0
    39069 2001 1.2176540716624848
    48287 2004 4.958586933358655
    32029 2009 0
    26153 2018 5.143457799512858
    45075 1994 9.57379445484874
    16035 2005 0
    31011 1992 0
    28149 2000 4.321489685003749
    13035 2009 5.974361924228128
    18073 2011 .9450858933050749
    6015 2018 0
    51037 2015 8.984297886483155
    27147 1997 0
    27049 2008 0
    13067 2013 4.701164015139189
    51159 1993 14.620163636790409
    39089 2005 8.184112577007898
    39163 2016 2.4540586853258834
    48445 2018 .6963915508620739
    51027 2006 5.2859444856956825
    24027 2010 6.122707200012632
    19051 2017 2.3441135458047433
    8083 2005 0
    42113 2001 5.187312146504406
    56041 2018 0
    54023 2005 5.9549667865153095
    39029 1995 18.985927939081332
    53033 2001 0
    46049 1993 0
    18137 2000 1.4777306127462335
    45009 1999 12.664375906164487
    20023 2013 .5515533579622898
    13309 1993 2.002209976264
    51099 1992 15.345255335826499
    48451 1996 .8065755481343524
    20063 2013 .5742913525481828
    42011 2003 9.746020771666586
    42081 1991 7.651672616950649
    41067 1996 0
    48467 2016 .9597227343600853
    13209 1993 2.161048144059933
    47189 2009 2.6381215284462027
    42083 2004 16.365879229241905
    16043 2001 0
    31161 1993 0
    31171 2013 0
    39087 1992 3.0171433556186242
    53049 2011 0
    46025 2007 0
    39147 2011 1.8476320540024258
    26151 2002 3.9901194919252436
    end
    [/CODE]

  • #2
    Your question is rather unclear: you do not say what is unsatisfactory about the results you get. Also, your data example is not very helpful because, except for one fips, you have only one observation per fips, so it is impossible to work with lagged values here.

    I'm not quite sure how to understand
    The logic of the variable is such that

    Min1 = Standardized_Windspeed_t-1 if Windspeed > 25 & < 49
    since there is no variable in the data that is named standardized_windspeed. The closest thing to it is vmax_sust, so that's what I'll go with.

    Code:
    xtset fips year
    forvalues i=1/15 {
        gen Min`i' = cond(l`i'.vmax_sust > 25 & l`i'.vmax_sust < 49, ///
            l`i'.vmax_sust, .)
    }
    Note that where the (lagged) value of vmax_sust is not in the 25-49 range, this code returns a missing value--this is just my interpretation of your definition as you do not specify what is wanted in that case. You can replace . with whatever you do want there.

    Comment


    • #3
      This question seems a variant on https://www.statalist.org/forums/for...cator-variable

      Please do not start a new thread so close to a previous thread without (at a minimum) a cross-reference in each thread to the other and an explanation of why you are doing that.

      Comment

      Working...
      X