Announcement

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

  • can we generate 0,1 and missing values simutaneously?

    Code:
    gen A = B==0 & C==1
    replace A = . if B== .| C==.
    In other words, can we simplify the two syntax above to one syntax?
    Thanks in advance.

  • #2
    Sure. Here is one, not necessarily the best, way

    Code:
    generate byte A = B==0 & C==1 if B!=. & C!=.

    Comment


    • #3
      Originally posted by daniel klein View Post
      Sure. Here is one, not necessarily the best, way

      Code:
      generate byte A = B==0 & C==1 if B!=. & C!=.
      Great, thanks!

      Comment


      • #4

        Code:
        generate byte A = B==0 & C==1 if !missing(B, C)
        is another approach but (NB!) not the same thing in the presence of extended missing values
        .a to .z FWIW, this nuance is also covered by FAQs https://www.stata.com/support/faqs/d...mmy-variables/ https://www.stata.com/support/faqs/d...rue-and-false/ and within a tutorial on indicator variables https://www.stata-journal.com/articl...article=dm0099

        Comment

        Working...
        X