Announcement

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

  • Row Mean

    Dear all,

    I am using Stata 16, on mac. I have taken a snapshot on the panel dataset I am working with.

    Click image for larger version

Name:	Screen Shot 2020-10-02 at 11.41.10 PM.png
Views:	1
Size:	12.1 KB
ID:	1575362

    I want to generate a new variable called RowMean, which is the arithmetic mean (the average) across all the of variables Participant Ever Smoked 1997? Participant Ever Smoked 1998? and Participant Ever Smoked 1999?. So for example in the first row under the Row Mean variable I would like to calculate the average in Stata: (1+-4+-4)/(3) = -2.3 I am unsure on how to write the Stata code for this?
    Thank you in advance for your help

    Jason Browen

  • #2

    .ÿclearÿ*

    .ÿquietlyÿsetÿobsÿ1

    .ÿinputÿint(smo1ÿsmo2ÿsmo3)

    ÿÿÿÿÿÿÿÿÿsmo1ÿÿÿÿÿÿsmo2ÿÿÿÿÿÿsmo3
    ÿÿ1.ÿ1ÿ-4ÿ-4

    .ÿegenÿdoubleÿrow_meanÿ=ÿrowmean(smo?)

    .ÿlist,ÿnoobs

    ÿÿ+---------------------------------+
    ÿÿ|ÿsmo1ÿÿÿsmo2ÿÿÿsmo3ÿÿÿÿÿrow_meanÿ|
    ÿÿ|---------------------------------|
    ÿÿ|ÿÿÿÿ1ÿÿÿÿÿ-4ÿÿÿÿÿ-4ÿÿÿ-2.3333333ÿ|
    ÿÿ+---------------------------------+

    .


    Code:
    help egen
    They look like coded nominal categories. Are you sure you want to do this?

    Comment


    • #3
      Thank you this isn't actually the dataset I am using I just wanted an example of the code I would use to get the average mean for a row.

      Comment


      • #4
        If you type in Stata


        Code:
        search row mean
        egen is the first suggestion.

        Comment


        • #5
          Thank you Nick

          Comment

          Working...
          X