Announcement

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

  • fsum order of the statistics

    Hello,

    Does anyone knows if it is possible to change the order of the statistics in a fsum table ?

    For example I have fsum X, stats (mean sd n).

    But I have this table:

    Variable______________________| N___ Mean___ SD
    ------------------------------------------------+---------------------------
    X __________________________| 148 7. 96 1.06

    And I would like something like:
    Variable______________________| Mean___ SD___ N
    ------------------------------------------------+---------------------------
    X __________________________| 7. 96 1.06 148

    Thank you very much,

    Grégoire
    Last edited by Gregoire Urvoy; 17 Apr 2016, 15:52.

  • #2
    tabstat lets you specify an order for the statistics shown.

    Code:
    .. sysuse auto, clear
    (1978 Automobile Data)
    
    . tabstat mpg, s(mean sd N) by(rep78)
    
    Summary for variables: mpg
         by categories of: rep78 (Repair Record 1978)
    
       rep78 |      mean        sd         N
    ---------+------------------------------
           1 |        21  4.242641         2
           2 |    19.125  3.758324         8
           3 |  19.43333  4.141325        30
           4 |  21.66667   4.93487        18
           5 |  27.36364  8.732385        11
    ---------+------------------------------
       Total |  21.28986  5.866408        69
    ----------------------------------------

    Comment


    • #3
      I know but I need to use fsum to have the labels in my table.

      Unfortunately, tabstat puts the name of the variable and not the label.

      Comment


      • #4
        What you want is programmable by yourself. e.g.

        Code:
        sysuse auto, clear  
        
        gen which = ""
        gen mean = .
        gen sd = .
        gen N = .
        
        local i = 0
        quietly foreach v in mpg weight turn trunk {
            local ++i
            replace which = "`: var label `v''" in `i'
            replace which = "`v'" in `i' if missing(which[`i'])
            su `v'
            replace mean = r(mean) in `i'
            replace sd = r(sd) in `i'
            replace N = r(N) in `i'
        }
        
        char which[varname] " "
        replace which = trim(which)
        format mean sd %2.1f
        l which-N in 1/`i', noobs subvarname  
        
          +---------------------------------------------+
          |                           mean      sd    N |
          |---------------------------------------------|
          |         Mileage (mpg)     21.3     5.8   74 |
          |         Weight (lbs.)   3019.5   777.2   74 |
          |     Turn Circle (ft.)     39.6     4.4   74 |
          | Trunk space (cu. ft.)     13.8     4.3   74 |
          +---------------------------------------------+
        
        
        tabdisp which in 1/4, c(mean sd N)
        
        ----------------------------------------------------------
                        which |       mean          sd           N
        ----------------------+-----------------------------------
                Mileage (mpg) |       21.3         5.8          74
        Trunk space (cu. ft.) |       13.8         4.3          74
            Turn Circle (ft.) |       39.6         4.4          74
                Weight (lbs.) |     3019.5       777.2          74
        ----------------------------------------------------------

        Comment


        • #5
          Thank you very much.

          I did it and it works perfectly well.

          I have a last problem: the labels are ordered alphabetically. Do you have any suggestions ?

          I could use the first table but I have this:

          Comment


          • #6
            And I would like to have something like this:

            Thank you so much for you help.

            Comment


            • #7
              You don't give which code you are using, but it seems the tabdisp code. Use the list code instead.

              Comment


              • #8
                My problem with the list code is the lines in the table.

                My problem with the tabdisp code is the fact that the labels are ordered alphabetically.

                Do you see what I mean ?

                Thank you

                Comment


                • #9
                  Quite. I think you need to write your own program or just get to work editing the output.
                  Last edited by Nick Cox; 18 Apr 2016, 04:09.

                  Comment


                  • #10
                    I am just a beginner on stata. So it looks a bit complicated for me. No worries, I will find something else.

                    Thank you for your time.

                    Comment


                    • #11
                      Ben Jann's estout and its wrapper program esttab have good facilities for formatting summary statistics (as well as regression estimates), and you may find them useful: seehttp://repec.org/bocode/e/estout/est...tml#estpost101. Download from SSC: ssc describe estout

                      Comment

                      Working...
                      X