Announcement

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

  • Generating means with missing or 0 value

    Hi, I am trying to plot a bar graph using variables averaged. My group variable is age cohorts in 5 years intervals. My averaged variable is hours worked by economists. When I do
    by agecohort sort: egen avghours_males=mean(hours) if economist==1 & sex==1
    I get the mean for those values that contain positive hours but exclude the 0 values. Is there any alternative to also include those who did work 0 hours or whose data is missing data?
    Thanks

  • #2
    0 values or missing values on which variables?

    Comment


    • #3
      in the variable "hours". The average I get excludes those 0 or missing to work out the mean.

      Comment


      • #4
        which is something weird when working out the mean. Clearly, I may be doing something wrong.
        Also tried to work out by getting total numbers for the number of economists & the number of hours. But did not work either.

        Comment


        • #5
          I see absolutely no reason to suppose that zeros on hours are being excluded. Try this

          Code:
           
          clear 
          set obs 2
          input hours
          42 
          0 
          end 
          egen mean = mean(hours)
          list
          The egen calculation will give the mean of 0 and 42. Nothing will exclude the zero. If you are convinced otherwise, you need to show us the evidence. Something else will be distracting you.

          But as for missings, what do you expect Stata to do?

          Here is some role reversal for you. Your job is to be Stata. Two people are asked on hours worked. One says 42, the other is too busy to answer your email, so their value is entered as missing. In what sense and how can your average include the missing value?

          Comment


          • #6
            Thanks Nick. I have been checking the results and your argument makes sense.

            Comment

            Working...
            X