Announcement

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

  • Compute totals by category stata

    Hello everybody,


    I am working right now on a big parlamentary database for my PhD (well actually a chapter of my phd), of the following form
    1 - name candidate - money received - company financing - other variables
    2 - James Smith - 900.000 - BigCompany
    3 - James Smith - 670.560 - BigCompany
    4 John Law - 356 - LittleCompany
    5 etc


    My question is:

    I would like to sum up the values for a certain candidate, and to add options, something like:
    tab value-received-from-BigCompany TOTALRECEIVEDBYCANDIDATE Candidate if Candidate=="Candidate1"


    do you see what i mean ?

    Or i would like to do the same with the frequency of "money received", if its easier.

    Is there any command to do so? If not, i can do it by hand maybe. Bigcomapny financed sometimes a candidate with 15 amounts of money, sometimes with 5 big amounts, it depends.


    Thanks a lot for your help,


  • #2
    Code:
    help tabstat

    Comment


    • #3
      thanks for your answer. I have to admit that this forum is perfect. Messy questions and clear answers.

      I did it, now, may I just ask if there is a way to put these results in a var ? SO i'll have something like this:

      canditate 1 - total received 320 - received big company 5 - var...
      candidate 2 - totalr eceived 450 - received bigcompany 12- var...
      candidate 1 - total received 320 - received bigcompany 17 - var


      Thanks

      Comment


      • #4
        Code:
        help egen

        Comment


        • #5
          should it be: egen totalreceived = fcn( tabstat total valor todoJBS if nomcan=="cand1" | nomcan=="cand2" |..., by(nomcan) stat(sum) ) ?

          Comment


          • #6
            Not at all. That's just fantasy syntax.

            You haven't given us a dataset example (Stata FAQ #12.1), but here is a nonsense example you can run and study:

            Code:
            . sysuse auto, clear
            (1978 Automobile Data)
            
            . egen totalweight = total(weight), by(foreign rep78)
            
            . by foreign: tabstat weight, s(sum) by(rep78)
            
            ---------------------------------------------------------------------------------------------
            -> foreign = Domestic
            
            Summary for variables: weight
                 by categories of: rep78 (Repair Record 1978)
            
               rep78 |       sum
            ---------+----------
                   1 |      6200
                   2 |     26830
                   3 |     92940
                   4 |     31790
                   5 |      3920
            ---------+----------
               Total |    161680
            --------------------
            
            ---------------------------------------------------------------------------------------------
            -> foreign = Foreign
            
            Summary for variables: weight
                 by categories of: rep78 (Repair Record 1978)
            
               rep78 |       sum
            ---------+----------
                   3 |      6030
                   4 |     19870
                   5 |     21630
            ---------+----------
               Total |     47530
            --------------------
            
            . tabdisp foreign rep78, c(totalweight)
            
            ----------------------------------------------------
                      |            Repair Record 1978           
             Car type |     1      2      3      4      5      .
            ----------+-----------------------------------------
             Domestic |  6200  26830  92940  31790   3920  10810
              Foreign |                6030  19870  21630   3420
            ----------------------------------------------------


            Comment


            • #7
              thanks ! i think i managed to do it!

              Comment

              Working...
              X