Announcement

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

  • Adding in stata with some missing

    Hi I was wondering if anyone can help with coding. I'm struggling a bit with this.

    I'm trying to add up a set of variables (9 in total) representing 9 different questions.

    I want stata to add it if the respondent has answered atleast 6 of the 9 question but not to add it if it doesn't have atleast 6.

    Can anyone please advise many Thanks

  • #2
    Dee:
    do you mean something along the following lines?:
    Code:
    . set obs 3
    number of observations (_N) was 0, now 3
    
    . g id=_n
    
    . g A=1 in 1/2
    (1 missing value generated)
    
    . g B=1 in 2/3
    (1 missing value generated)
    
    . g C=1
    
    . egen flag=rownonmiss(A B C)
    
    . list
    
         +-----------------------+
         | id   A   B   C   flag |
         |-----------------------|
      1. |  1   1   .   1      2 |
      2. |  2   1   1   1      3 |
      3. |  3   .   1   1      2 |
         +-----------------------+
    
    . keep if flag>=3
    (2 observations deleted)
    
    . list
    
         +-----------------------+
         | id   A   B   C   flag |
         |-----------------------|
      1. |  2   1   1   1      3 |
         +-----------------------+
    
    .
    Kind regards,
    Carlo
    (Stata 19.0)

    Comment


    • #3
      Thanks Carlo, not quite though. The question is a yes or no answer with yes=1 and no=0. I would also want it to add it up even if it has 6 no's

      Comment


      • #4
        Carlo Lazzaro has given you the main idea. His code is not broken by zeros in the data. Suppose your variables are A B C D E F G H I.

        Then

        Code:
        egen present = rownonmiss(A B C D E F G H I) 
        egen wanted  = rowtotal(A B C D E F G H I) if present >= 6

        Comment


        • #5
          That said, a row mean would appeal more to me here. Otherwise you are trying to compare (e.g.) a total of 6 from 6 and 6 from 9.

          Comment

          Working...
          X