Announcement

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

  • fsum - additional statistics

    Hi,

    I am generating simple summary using the fsum command below.
    Code:
    fsum `sumvars', uselabel stats(p5 mean median p95)
    I would like to produce additional statistics for p10 and p90 but those statistics appear not be available via the fsum. Is there any way, I could work around this problem? With respect to the task at hand, the output generated by fsum suits me perfectly, especially the option uselabel proves extremely handy. The only functionality I am missing here is concerned with additional statistics that I have to presently produce.
    Kind regards,
    Konrad
    Version: Stata/IC 13.1

  • #2
    Konrad,

    fsum is a user-written command available from SSC, which you should have mentioned. There are several options here:
    1. Contact the author of fsum and request that p10 and p90 be added. Since these are available with summarize, it stands to reason that fsum should include them as well.
    2. Write some code that does what you want without fsum. You could look at the fsum code for guidance, although that probably isn't necessary. See below for a start:
    3. Find another program that does what you want. Maybe tabout, although it is overkill for what you want to do.
    Code:
    foreach var of varlist `sumvars' {
      local varl : var label `var'
      qui sum `var',  det
      di "`varl'" r(N) %10.0f r(p5) %10.1f r(p10) %10.1f r(mean) %10.1f r(p50) %10.1f r(p90) %10.1f r(p95) %10.1f
    }
    No doubt you will want to add some more formatting to make the results more readable, but this is the basic idea.

    Regards,
    Joe

    Comment


    • #3
      Joe,

      Thanks for getting back to me, I use tabout from time to time but I agree with your point that this would be an overkill for such a primitive task. I searched for alternatives but findit and Google search did not return satisfactory results, was hoping that maybe someone will suggest some neat programme hidden somewhere on ssc. Either way, thanks for showing the interest.
      Kind regards,
      Konrad
      Version: Stata/IC 13.1

      Comment


      • #4
        I'm the author of fsum. I'll see if I can find some time and update it to include P10 and P50.

        Fred

        Comment


        • #5
          Fred,

          Thank you very much, this would be greatly appreciated.
          Kind regards,
          Konrad
          Version: Stata/IC 13.1

          Comment


          • #6
            Meanwhile, no one mentioned tabstat....

            Code:
            . sysuse auto
            (1978 Automobile Data)
            
            . tabstat trunk turn mpg, s(mean median p5 p10 p90 p95) f(%10.1f) c(s)
            
                variable |      mean       p50        p5       p10       p90       p95
            -------------+------------------------------------------------------------
                   trunk |      13.8      14.0       7.0       8.0      20.0      21.0
                    turn |      39.6      40.0      33.0      34.0      45.0      46.0
                     mpg |      21.3      20.0      14.0      14.0      29.0      34.0
            --------------------------------------------------------------------------

            Comment


            • #7
              Nick,

              thanks for the suggestion. From my perspective, tabstat would be an ideal if not lack of variable labels.In the context of this particular task, fsum is the ideal solution as it lets me to share the output directly from Stata with one line of code. Using tabstat would force me to access r() values and export them maybe to Excel via putexcel, or use tabout. All of that is appears to be rather unnecessary in the light of simple difficulty concerned with displaying variable labels instead of variable names.
              Kind regards,
              Konrad
              Version: Stata/IC 13.1

              Comment


              • #8
                I don't understand your reply except for the detail that you want variable labels too. Depending on how often you want to do this, the answer ranges from "just copy and paste the variable labels" to "that's programmable".

                Comment


                • #9
                  I think that's programmable is most accurate. To be honest, it's a matter of convenience. I'm looking for a way to effortlessly produce a simple summary table with variable labels as variable names are not sufficient.
                  Kind regards,
                  Konrad
                  Version: Stata/IC 13.1

                  Comment


                  • #10
                    It's always nice to find "effortless" solutions, and perhaps Fred Wolfe will come to your rescue eventually. Depending on your interest in learning Stata programming skills, this might be an ideal project: to learn enough about Stata programming to be able to write your own command that does what you want. The basics are given in my post above; you just need to pretty up the output and add a few lines to provide a useful user interface (see the program and syntax commands). This might take a few hours for the beginning programmer, but it will be time well spent, because in the end you will have an effortless solution to your original problem and you will know how to solve similar problems in the future.

                    Comment


                    • #11
                      I did not write tabstat, but it is easy to speculate that it lacks an option to show variable labels because the programmer was thinking that variable labels can be much longer than there may be space for, given listing possibly several summary statistics. That doesn't rule an option being added so that users can make their choice if they have enough space.

                      Comment


                      • #12
                        Originally posted by Joe Canner View Post
                        It's always nice to find "effortless" solutions, and perhaps Fred Wolfe will come to your rescue eventually. Depending on your interest in learning Stata programming skills, this might be an ideal project: to learn enough about Stata programming to be able to write your own command that does what you want.
                        I definitely agree with this, I like to program but mostly do that in IronPython due to its integration with .NET (work requirements). Personally, Stata is my package of choice and I would like to program in it.
                        Kind regards,
                        Konrad
                        Version: Stata/IC 13.1

                        Comment


                        • #13
                          Colleagues, Following the previous discussion on Statalist and Kevin's blog post below is a primitive code that uses tabstat and the user-written programme tabstatmat to export the desired table to Excel.
                          Code:
                          tabstat `sumvars', s(mean median p10 p90) f(%10.1f) c(s) save
                          tabstatmat temp
                          matrix temp = temp'
                          putexcel B2=matrix(temp, names) using summary, replace
                          local i = 3
                          foreach var of varlist `sumvars' {
                            local varlabel : variable label `var'
                            putexcel B`i'= ("`varlabel'") using summary, modify
                            local i = `i' + 1 }
                          Personally, I would still rather use fsum and print the table from Stata without opening the Excel but this does the job.
                          Kind regards,
                          Konrad
                          Version: Stata/IC 13.1

                          Comment


                          • #14
                            I have revised fsum to work as you wished. I have sent it on to Kit Baum at SSC. I'll let you know when it becomes available.
                            Fred

                            Comment


                            • #15
                              It is now available. ssc install fsum, replace. For technical reasons, if you request P10 you should also request P1.
                              Fred

                              Comment

                              Working...
                              X