Announcement

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

  • create sum of group of data

    Hi all,

    I need create new variables : sum for pooled data, each independent of other.

    Here i attach more detail of my original data and my desire results.

    Thanks in advance.

    Regard Rodrigo
    Last edited by Rodrigo Badilla; 07 May 2014, 22:37.

  • #2
    Your photo is unreadable, to me at least. I think you will get more readable results by attaching listings as code.

    As earlier requested, please identify yourself using your full real name, which I guess to be Rodrigo Badilla.

    Comment


    • #3
      Please use your full real name. Use the CONTACT US link to ask the administrators to change it.

      Here's some code:

      Code:
      clear all
      set more off
      
      *------  example data -----
      
      input ///
      pred1 pred2 pred3
      . . .
      . 3 .
      . 2 .
      . . .
      5 . .
      7 . .
      . . 4
      . . 4
      1 . .
      3 . .
      2 . .
      end
      
      list, sep(0)
      
      *------ what you want -----
      
      gen ord = _n
      foreach v of varlist pred1-pred3 {
      
          * create a variable that flags each "group"
          gen `v'i = sum(!missing(`v') & missing(`v'[_n-1]))
          replace `v'i = 0 if missing(`v')
          
          * compute totals by group
          bysort `v'i: egen `v't = total(`v')
          drop `v'i // drop group variable
          
          * sort back to original order to work on next variable
          sort ord
      }
      
      drop ord
      list, sep(0)
      Last edited by Roberto Ferrer; 08 May 2014, 17:04.
      You should:

      1. Read the FAQ carefully.

      2. "Say exactly what you typed and exactly what Stata typed (or did) in response. N.B. exactly!"

      3. Describe your dataset. Use list to list data when you are doing so. Use input to type in your own dataset fragment that others can experiment with.

      4. Use the advanced editing options to appropriately format quotes, data, code and Stata output. The advanced options can be toggled on/off using the A button in the top right corner of the text editor.

      Comment


      • #4
        Thanks Roberto for you reply, I made my request to change in my nick name.to administrators
        regards
        Last edited by Rodrigo Badilla; 08 May 2014, 19:49.

        Comment


        • #5
          Hi Roberto,

          Your command work so fine!!, thanks for your command!

          Regards

          Comment


          • #6
            Glad it worked.

            Thanks for soliciting a more adequate user name.
            You should:

            1. Read the FAQ carefully.

            2. "Say exactly what you typed and exactly what Stata typed (or did) in response. N.B. exactly!"

            3. Describe your dataset. Use list to list data when you are doing so. Use input to type in your own dataset fragment that others can experiment with.

            4. Use the advanced editing options to appropriately format quotes, data, code and Stata output. The advanced options can be toggled on/off using the A button in the top right corner of the text editor.

            Comment

            Working...
            X