Announcement

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

  • gen dummy with missing data

    Dear All, Suppose that I run the code
    Code:
    sysuse auto, clear
    gen d = (rep78 > 2) & !missing(rep78)
    i.e., d-=1, if rep78 > 2 (3,4,5) and d=0 if rep78 <= 2 (1,2). My problem is that I want d =. if rep78 = . (missing). Any suggestions (hopefully, in one line)? Thanks.
    Ho-Chuan (River) Huang
    Stata 19.0, MP(4)

  • #2
    River, if your code is as follows, then d has already been "." for rep78 == .

    Code:
    sysuse auto, clear
    gen d = (rep78 > 2) if !missing(rep78)

    Comment


    • #3
      Dear Fei, Thanks. I should have used "if" instead of "and" in the command.
      Ho-Chuan (River) Huang
      Stata 19.0, MP(4)

      Comment


      • #4
        This has been an FAQ for a long time.

        https://www.stata.com/support/faqs/d...mmy-variables/

        Our own FAQ prompts you to scan the FAQs before posting https://www.statalist.org/forums/help#before

        For a longer discussion of indicator variables, including why that term is better, see https://www.stata-journal.com/articl...article=dm0099

        If that is behind a paywall as far as you are concerned, then that will end in March 2022.

        Comment


        • #5
          Dear Nick, Got it and thanks.
          Ho-Chuan (River) Huang
          Stata 19.0, MP(4)

          Comment

          Working...
          X