Announcement

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

  • Compute a mean index only for cases having at least 3 valid values over 4 variables


    Hey everyone, I am using Stata Version 14.2. I want to compute a mean index over 4 variables but only count cases having at least 3 non missing values on those 4 variables. In SPSS you can specifiy this by setting the valid case number(3)
    Code:
    compute Marktf = mean.3 (emp05, emp06, ok02, ok01).
    Is there a way to transfer this SPSS code to Stata?

  • #2
    use the min option in the alpha command. See
    Code:
    help alpha

    Comment


    • #3
      maybe I don't understand what a "mean index" is, but I don't see that -alpha- does what I think it means; try this (assuming that all variables are present within an observation):
      Code:
      egen numthere=rownonmiss(emp05 emp06 ok02 ok01)
      egen meanindex=rowmean(emp05 emp06 ok02 ok01) if numthere>=3

      Comment


      • #4
        Originally posted by Rich Goldstein View Post
        maybe I don't understand what a "mean index" is, but I don't see that -alpha- does what I think it means; try this (assuming that all variables are present within an observation):
        Code:
        egen numthere=rownonmiss(emp05 emp06 ok02 ok01)
        egen meanindex=rowmean(emp05 emp06 ok02 ok01) if numthere>=3
        Alpha produces the same variable as your egen commands, but also has the possibility of producing some usable index statistics like Cronbach's Alpha or item-rest-correlation:

        Code:
        sysuse auto, clear
        alpha length turn displacement weight, min(3) gen(index1) item
        
        egen numthere=rownonmiss(length turn displacement weight)
        egen index2=rowmean(length turn displacement weight) if numthere>=3
        
        pwcorr index*
        browse index*

        Comment


        • #5
          Thank you so much Emil Alnor and Rich Goldstein!

          Both codes you shared actually produced the same accurate new variable.

          I didn't know that the 'alpha command' could be used to generate new variables. Thanks for enlightening me.

          Regarding the 'mean index', what I meant was that I intended to create a new variable by computing the mean. I apologize for any confusion I may have caused.

          Comment

          Working...
          X