Announcement

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

  • creating new variable

    Hi all,

    I would like to generate a new variable from 2 variables: b_macob and b_pacob

    i input :

    generate S = (if b_pacob >=5 | if b_macob >=5)

    however it returns "ifb_pacob not found"

    please what is my mistake and how do i fix it?


  • #2
    Nene:
    welcome to this forum.
    Your Stata code is illegal;
    Code:
    . use "C:\Program Files\Stata17\ado\base\a\auto.dta"
    (1978 automobile data)
    
    . gen wanted=(if price >=5 | if mpg >=5)
    ifprice not found
    r(111);
    You should try something along the following lines, I guess:
    Code:
    . gen wanted=price if price>=5
    
    . replace wanted=mpg if mpg >=5
    Kind regards,
    Carlo
    (Stata 19.0)

    Comment


    • #3
      thank you Carlo!

      Comment


      • #4
        Or just exclude the "if" part in your command.

        Code:
        generate S = (b_pacob >=5 | b_macob >=5)

        Comment


        • #5
          Nene:
          George's helpful code is more efficient than mine.
          Kind regards,
          Carlo
          (Stata 19.0)

          Comment


          • #6
            Note that

            b_pacob >=5 | b_macob >=5 will return 1 if either variable is missing (or both).

            Comment


            • #7
              Nick:
              yes, I saw it and wondered what kind of indicator the original poster was after.
              I'm probably becoming a tad old-fogey (and increasingly so) as time goes by, but I still prefer to go step-by-step when it comes to derive variables from other variables.
              Kind regards,
              Carlo
              (Stata 19.0)

              Comment


              • #8
                Carlo Lazzaro Compare Wyatt Earp: Fast is fine, but accuracy is final (various mutations are reported).

                Comment


                • #9
                  Originally posted by Nick Cox View Post
                  Carlo Lazzaro Compare Wyatt Earp: Fast is fine, but accuracy is final (various mutations are reported).
                  Thanks for that, Nick.
                  Various versions indeed.
                  An old Italian saying, which sounds as the opposite of today's hectic (and often unhealthy) lifestyles, goes like that (+/-): "Who goes slowly, goes healthy and far".
                  Kind regards,
                  Carlo
                  (Stata 19.0)

                  Comment

                  Working...
                  X