Announcement

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

  • Deleting Observations

    Hi Everyone,
    Please what code should I use if I want to have only observations where participants responded "Yes" to suicidal ideation, "Yes" to suicidal plan and then indicated the number of times they attempted suicide? I tried to use the drop if command, but it deleted all the participants who responded "No" and I cannot do a regression analysis if all those with "No" are deleted.

    Ideation Plan Number of time attempted.
    1531. Yes No 0 times
    1532. No Yes 2 or 3 times
    1533. No No 0 times
    1534. Yes Yes 1 time
    1535. No No 0 times

    In the table above, how do delete observations/participants 1531, 1532, 1533, and 1535? I hope this clarifies things.

    Thank you for your help in advance.

  • #2
    Data example please using dataex -- the answer depends crucially on whether these variables are string or numeric with value labels.

    See https://www.statalist.org/forums/help#stata

    Comment


    • #3
      Thanks, Nick for your response. I am not sure about how to use the dataex command. The variables are numeric with value labels. Thanks

      Comment


      • #4
        Code:
        help dataex
        That's not precise enough for me to suggest precise code.

        Comment


        • #5
          Hi Nick, I used dataex and generated this. I hope it clarifies my question. Thank you
          Code:
          * Example generated by -dataex-. For more info, type help dataex
          clear
          input byte(Q24 Q25 Q26)
          2 2 1
          1 2 4
          . 2 3
          2 2 2
          2 2 1
          . 1 4
          2 . 1
          2 2 1
          2 2 1
          . . 1
          2 2 1
          . . 1
          2 2 1
          2 2 1
          2 2 1
          2 2 1
          1 2 1
          2 2 1
          2 2 1
          2 1 1
          2 2 1
          2 2 1
          2 2 1
          2 2 1
          2 1 1
          2 2 1
          2 2 1
          2 2 1
          2 2 1
          1 1 2
          2 2 1
          2 2 1
          2 2 1
          2 2 1
          2 . .
          2 2 1
          2 2 1
          2 2 1
          2 2 1
          2 2 1
          2 2 1
          2 1 1
          2 2 1
          2 2 2
          2 2 1
          2 1 1
          2 1 1
          2 2 1
          2 2 1
          2 2 1
          2 2 1
          2 2 1
          2 2 1
          2 2 1
          2 2 1
          2 2 1
          2 2 1
          1 1 1
          2 2 1
          2 2 1
          2 2 1
          2 2 1
          2 2 1
          2 2 1
          2 2 1
          2 2 1
          2 2 1
          2 2 1
          2 2 1
          2 2 1
          2 2 1
          2 1 2
          1 1 3
          2 2 1
          2 2 1
          2 2 1
          1 1 1
          1 1 2
          2 2 1
          2 2 1
          2 2 1
          2 2 1
          2 2 .
          1 1 1
          1 1 3
          2 2 1
          1 2 1
          1 1 5
          2 2 1
          2 2 1
          2 2 1
          2 . 2
          2 2 1
          1 1 2
          2 2 1
          2 2 1
          2 2 1
          2 2 1
          1 1 3
          2 2 1
          end
          label values Q24 Q24
          label def Q24 1 "Yes", modify
          label def Q24 2 "No", modify
          label values Q25 Q25
          label def Q25 1 "Yes", modify
          label def Q25 2 "No", modify
          label values Q26 Q26
          label def Q26 1 "0 times", modify
          label def Q26 2 "1 time", modify
          label def Q26 3 "2 or 3 times", modify
          label def Q26 4 "4 or 5 times", modify
          label def Q26 5 "6 or more times", modify

          Comment


          • #6
            Thanks for the detail.

            Code:
            keep if Q24 == 1 & Q25 == 1
            seems to be what you're asking for. Missings on Q26 will be ignored any way in model fitting. But why do that? Just call up your model fitting command with


            Code:
            ....  if Q24 == 1 & Q25 == 1

            Comment


            • #7
              Thanks Nick. The idea is to have participants who responded to Yes to Q24 and Q24 and went on to respond to Q26 by indicating the number of times. Then do a regression to see what factors are associated. At the moment, when I use the command suggested, it deletes all "No" responses and regression can't be done. See below the output when i attempted doing regression.

              . regress Q24 i.Q2 i.Q1

              Source | SS df MS Number of obs = 270
              -------------+---------------------------------- F(8, 261) = .
              Model | 0 8 0 Prob > F = .
              Residual | 0 261 0 R-squared = .
              -------------+---------------------------------- Adj R-squared = .
              Total | 0 269 0 Root MSE = 0

              ----------------------------------------------------------------------------------------
              Q24 | Coefficient Std. err. t P>|t| [95% conf. interval]
              -----------------------+----------------------------------------------------------------
              Q2 |
              Female | 0 (omitted)
              |
              Q1 |
              12 years old | 0 (omitted)
              13 years old | 0 (omitted)
              14 years old | 0 (omitted)
              15 years old | 0 (omitted)
              16 years old | 0 (omitted)
              17 years old | 0 (omitted)
              18 years old or older | 0 (omitted)
              |
              _cons | 1 . . . . .
              ----------------------------------------------------------------------------------------

              Comment


              • #8
                Indeed. I thought you had other covariates but once you reduce any covariate to a constant it can't appear in a regression. You need to use all the relevant data.

                Comment


                • #9
                  Thanks for your assistance Nick.

                  Comment

                  Working...
                  X