Announcement

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

  • Divide total of varlist through another

    Hello everybody,

    this is my data example:
    died_c surv_c op_pan op_liv
    1 0 0 0
    0 1 0 0
    0 1 1 0
    0 0 0 0
    0 0 0 1
    0 0 0 0
    1 0 1 0
    0 1 0 0
    a) I would like to divide the total of died_c through the total of surv_c.

    b) second I would like to divide for all observations op_pan ==1 the total of died_c the total surv_c.

    I either tried to use some tab syntax or to create a newvar with the total of died_c/surv_c. Unfortunatly I didn't find a solution.
    Your inputs would be very helpful. Thank you in advance.

  • #2
    Look at egen with total to do your sum. Then, you can use an if condition at the end of generate to do the division.
    something like:
    su died_c
    local totdied_c=r(sum)
    g ratio=surv_c/`totdied'

    And can do
    g ratio1=surv_c/`totdied' if op_pan==1

    Comment


    • #3
      Thank you for your help. The code
      g ratio=surv_c/`totdied'
      gives me an r198 Error, any clue why?

      I've tried
      Code:
       gen ratio= surv_c/surv_c
      but this code divides each observation through another.

      Comment

      Working...
      X