Announcement

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

  • Mean if respondents have answerd atleast out of 3 variables

    Hi I would reaaly be grateful if anyone can help with providing a code for this.

    I have 3 sets of variables relating to the same thing. I was wondering what code I can use to calculate the mean of these variables if the respondents answered at least 2 of them. Many Thanks

  • #2
    Where you say "3 sets of variables" I am going to guess that you mean "3 variables". Type
    Code:
    help egen

    to find about rowmean() and rowmiss(). It sounds as if you want something with this flavour

    Code:
    egen wanted = rowmean(q1 q2 q3)
    egen missing = rowmiss(q1 q2 q3)
    replace wanted = . if missing > 1
    In fact you can do it in one line

    Code:
    egen wanted = rowmean(q1 q2 q3) if (missing(q1) + missing(q2) + missing(q3)) <= 1
    or

    Code:
    egen wanted = rowmean(q1 q2 q3) if (!missing(q1) + !missing(q2) + !missing(q3)) >= 2
    Last edited by Nick Cox; 30 Apr 2019, 03:02.

    Comment


    • #3
      This worked fine, mant thanks

      Comment

      Working...
      X