Announcement

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

  • Generating new variable for each case (sum of several variables)

    I would appreciate your help:

    I am looking to generate a new variable that is a sum of several continuous variables and a substraction of one (or more). The total value needs to be calculated for each individual case (row) separately.

    For example:

    (ID_01) var01 + var02 +var03 - var04 = new_variable
    (ID_02) var01 + var02 +var03 - var04 = new_variable
    (ID_03) var01 + var02 +var03 - var04 = new_variable

    What would be the best approach. I have attempted this following guidance but I seem to get a total for all individual cases.

  • #2
    you neither show what you tried nor provide a data example (please read the FAQ), but this should be straightforward using the -generate- command; see
    Code:
    h gen
    note, in the help file, the ability set the type so that you can set to long or even double if needed

    Comment


    • #3
      The syntax is the same for each identifier if I understand you correctly

      Code:
      gen wanted = var01 + var02 +var03 - var04
      If you're still puzzled, you may need to show the syntax you did use. Or a data example with real(istic) data and the desired result.

      Comment

      Working...
      X