Announcement

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

  • Sum of variables

    I'm sorry for put here this easy question, but i'm having difficulty to do that.

    So, i have this three rows

    ............Row 1 Row 2 Row 3 Sum of Rows
    Line 1 - .... 2 ....... 4 ..... 6 ......... 12

    How can i generate the variable "Sum of Rows"?

    ​Thank you
    Last edited by RicardoRibeiro; 17 Dec 2014, 14:37.

  • #2
    See for row totals,

    Code:
    help egen

    Comment


    • #3
      Originally posted by Nick Cox View Post
      See for row totals,

      Code:
      help egen


      Sorry, I was not clear. Imagine that i just want to sum the last 2 rows, row 2 and 3, I don't want to sum the first one. How can i limit the sum just for this two variables?

      Comment


      • #4
        Originally posted by Nick Cox View Post
        See for row totals,

        Code:
        help egen

        Thank you, I think I reached what i want.

        Comment


        • #5
          I'm confused. Can't you just
          Code:
          gen sum=row2+row3
          If your actual problem is more difficult than this you should explain more clearly exactly what data you have and what you want to achieve. Reread the FAQ (link in the upper left of the page) for more helpful advice on how to ask questions in a way that makes it easier for us to help you.

          Comment


          • #6
            Originally posted by Sarah Edgington View Post
            I'm confused. Can't you just
            Code:
            gen sum=row2+row3
            If your actual problem is more difficult than this you should explain more clearly exactly what data you have and what you want to achieve. Reread the FAQ (link in the upper left of the page) for more helpful advice on how to ask questions in a way that makes it easier for us to help you.


            Yes, but i have much more variables, and I didn't want to do it by hand, select one by one.

            First time I did:

            gen sum= row*

            Stata didn't allow me to do that, but now I did:

            egen sum = rowtotal (row*)

            and it's working.

            Comment


            • #7
              I am confused too. A row is horizontal. A column is vertical. Stata uses the terms observation and variable any way. Concrete examples usually trump schematic examples. Show us some real(istic) examples. Don't abstract; you're not in mathematics class!

              Comment


              • #8
                Originally posted by Nick Cox View Post
                I am confused too. A row is horizontal. A column is vertical. Stata uses the terms observation and variable any way. Concrete examples usually trump schematic examples. Show us some real(istic) examples. Don't abstract; you're not in mathematics class!


                Sorry, I made a confusion with the terms. Instead of row1, i wanted to say column1. But I already achieved what I wanted with your help, thank you!


                I have in attachment what i Wanted to do.

                Closeness is the sum of all diff (diff1, diff2, diff3,...) and i did by this way:

                egen closeness = rowtotal (diff*)

                Am I right?
                Attached Files

                Comment

                Working...
                X