Announcement

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

  • problem counting the observations after using "egen and rowtotal"

    Hi all.

    I am using Health and Retirement Study data which is a survey done every 2 years. In one of the waves, the answer to a series of questions (5-question satisfaction with life scale) uses a 6 point likert scale. All the other waves use a 7 point scale. My goal is to create new variables for the 5 likert scale questions where the scale is converted from 6 to 7. The klb003a/b/c/d/e are my original variables and the ones with the "_new" ending is the ones I am creating.

    generate klb003a_new=(6)*(klb003a-1)/(5)+1
    generate klb003b_new=(6)*(klb003b-1)/(5)+1
    generate klb003c_new=(6)*(klb003c-1)/(5)+1
    generate klb003d_new=(6)*(klb003d-1)/(5)+1
    generate klb003e_new=(6)*(klb003e-1)/(5)+1

    After this step, I want to create another variable summing all 5 questions into one single variable. I did it like this:

    egen lifesat06total_= rowtotal (klb003a_new klb003b_new klb003c_new klb003d_new klb003e_new)
    replace lifesat06total_=. if klb003a==. | klb003b==. | klb003c==. | klb003d==. | klb003e==.

    When I do "tab lifesat06total_" I do get a frequency table with all the cases and assigned values rangin from 5 to 35 including integers and noninteger numbers due to the conversion.

    But when I do "count if lifesat06total_==33.8" I get this:

    count if lifesat06total_==33.8
    0

    Why is this happening? I know there are observation where the value is equal to 33.8. So getting 0 is wrong. I need to fix this because my final goal is to create a categorical variable (6 categories for life satisfaction) using the lifesat06total_.

    Thank you in advance.
    Last edited by Duygu Basaran Sahin; 10 Oct 2022, 09:21.

  • #2
    This is an issue of precision. What may seem like 33.8 to you is not exactly that to Stata. See
    Code:
    help precision
    Try something like:

    Code:
    count if lifesat06total_ == float(33.8)

    Comment


    • #3
      Thank you Hemanshu. There are many more cases like this though, do I just keep adding all the values in parantheses such as "float (33.8) (26.6) (21.8) etc. The total N is 7,332.

      Comment


      • #4
        You may need to think a little about what you are trying to do overall.

        my final goal is to create a categorical variable (6 categories for life satisfaction) using the lifesat06total_.
        Categorical variables in Stata should only take on integer values. One way to do this might be to

        Code:
        egen wanted = group(lifesat06total_), label

        Comment


        • #5
          Thank you. My categories will be integers, using values from the lifesat06total_ such as anything between 30-35=6 (extremely satisfied with life).

          Comment


          • #6
            So that should work fine, with commands like:

            Code:
            gen byte wanted = 6 if inrange(lifesat06total_,30,35)
            replace wanted = 5 if ...
            ...

            Comment

            Working...
            X