Announcement

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

  • Generating a Treatment Binary Indicator Variable

    I want to create six different categorical variables that capture a treatment of varying intensities and time lags (I just mention one of them here). The way I want to create them are as follows:

    Min_13 = 1 if Treat_t-1 > 25 & Treat_t-1 <49 | Treat_t-2 > 25 & Treat_t-2 <49 | Treat_t-3 > 25 & Treat_t-3 <49
    replace Min_13 = 0, if missing (Min_13)

    How can I run a loop to do this?

    Here's a code chunk that I try, but I do not think it is right ---->

    by fips year, sort: gen Surface_Min_t1_3 = cond(max(Hurr_Surface1, Hurr_Surface2, Hurr_Surface3)>25 & max(Hurr_Surface1, Hurr_Surface2, Hurr_Surface3)<49,1,0) // Any hurricane that causes windspeeds >50kts & < 96kts

  • #2
    This raises as many questions as it answers. What is Treat_t-1 as it can't be a variable name with a hyphen character? Perhaps it should be a variable name, or it's intended as pseudo-code for the previous value of some variable, but we shouldn't have to guess.

    Further, what is the relation between your definition and the code?

    Further, the comment refers to (50, 96) as an interval but the code refers to (25, 49).

    We would be just be guessing without a data example and clarification of obscurities and inconsistencies.

    From some familiarity with meteorological data and otherwise, I would guess >= 25 and <= 49 myself as a more likely criterion, but a key detail is whether windspeeds in your data are always reported as integer knots.

    In total, my wild guess would be

    Code:
    gen wanted = inrange(Hurr_Surface1, 25, 49) | inrange(Hurr_Surface2, 25, 49) | inrange(Hurr_Surface3, 25, 49)
    No loop needed, no two-step needed;
    fips and year not obviously relevant if you're working observation by observation.
    Last edited by Nick Cox; 12 Dec 2023, 05:52.

    Comment


    • #3
      See also https://www.statalist.org/forums/for...ment-variables

      Comment

      Working...
      X