Announcement

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

  • Sum of several variables calculated into one newly created variable...

    I have used SPSS in the past, and new to STATA . No statistical background per se, but a social researcher.
    Need some help on how to create a new variable that calculates automatically the sum of several variables put together.

    i have asked interviewees which month of the year they worked in the field - so, in Stata; for each month ( january to December), i have a variable - and 0 for not worked , 1 for worked.
    I want now to calculate how many months in the year they worked, which logically should be the sum of all months put together. so sum ( var1+var2+...)
    However , when computing this command, i obtain results that dont look like what i expected.

    Any advice on how to do this ( in lay language please)?

    Thanks

  • #2
    Code:
    gen monthsworked = var1 + var2 + var3 + ...
    or

    Code:
    egen monthsworked = rowtotal(var1 var2 var3 var4 ...)
    ---------------------------------
    Maarten L. Buis
    University of Konstanz
    Department of history and sociology
    box 40
    78457 Konstanz
    Germany
    http://www.maartenbuis.nl
    ---------------------------------

    Comment


    • #3
      Great! Thank you .... it worked perfect!

      Comment


      • #4
        It is hard to see what you did but note that the function sum() gives you a cumulative or running sum combining results across different observations. For sums within the same observations it will give incorrect results almost everywhere.

        Comment

        Working...
        X