Announcement

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

  • summarize , set wider column for variables

    Good evening,
    I would really appreciate reading the full name of variables when I use summarise instead of name interrupted by ~ (eg: "T23_~c_MF_PT"). But I cannot find a command or option which works for summarise .
    Somebody could help me in setting wider columns for the output in stata ?

    Many thanks in advance for your help.

  • #2
    I don't think this is possible with -summarize-. You can get the same information from -tabstat-, which does have a -varwidth()- option that allow you to allocate space more to your liking.

    Comment


    • #3
      Clyde has answered this query with the most accessible solution
      regardless of the version of Stata you use.

      However, if you have Stata 17 or newer, want more control over the look
      of your table of summary statistics, and are willing to write/modify
      your own Stata command, then consider the following program that uses
      collect and table to produce a customizable table of
      summary statistics.

      Code:
      program custom_summarize
              version 17
              syntax varlist(numeric)         ///
                      [if] [in] [fw aw iw] [, ///
                              name(name)      /// collection name
                              replace         ///
                      ]
      
              * start a new collection
              if "`name'" == "" {
                      * default collection name
                      local name custom_summarize
              }
              if "`name'" == "custom_summarize" {
                      * assume we can always overwrite/replace our default
                      * collection name
                      local replace replace
              }
              collect create `name', `replace'
      
              * custom styles and labels for output
              collect style clear
              * see -help predefined styles-
              collect style use default_halign
              collect style use table_headers
              collect style use default_margins
              collect style use table_nformats
              collect style use default_smcl
              * set borders like -summarize-
              collect style cell border_block[corner row-header], ///
                      nowarn border(right)
              collect style cell border_block[corner column-header], ///
                      nowarn border(bottom)
              * set result labels like -summarize-
              collect label levels result ///
                      count "Obs" ///
                      sd "Std. dev." ///
                      min "Min" ///
                      max "Max"
      
              * compute statistics and report them
              table (var) (result) `if' `in' [`weight'`exp'], ///
                      statistic(count `varlist')              ///
                      statistic(mean `varlist')               ///
                      statistic(sd `varlist')                 ///
                      statistic(min `varlist')                ///
                      statistic(max `varlist')                ///
                      name(`name') append
      end
      Here is an example of this command in action using the auto data.
      Code:
      . sysuse auto
      (1978 automobile data)
      
      . 
      . summarize mpg turn trunk rep for
      
          Variable |        Obs        Mean    Std. dev.       Min        Max
      -------------+---------------------------------------------------------
               mpg |         74     21.2973    5.785503         12         41
              turn |         74    39.64865    4.399354         31         51
             trunk |         74    13.75676    4.277404          5         23
             rep78 |         69    3.405797    .9899323          1          5
           foreign |         74    .2972973    .4601885          0          1
      
      . custom_summarize mpg turn trunk rep for
      (current collection is custom_summarize)
      
                            |  Obs       Mean   Std. dev.   Min   Max
      ----------------------+----------------------------------------
      Mileage (mpg)         |   74    21.2973    5.785503    12    41
      Turn circle (ft.)     |   74   39.64865    4.399354    31    51
      Trunk space (cu. ft.) |   74   13.75676    4.277404     5    23
      Repair record 1978    |   69   3.405797    .9899323     1     5
      Car origin            |   74   .2972973    .4601885     0     1
      
      . * change some numeric formats
      . collect style cell result[mean sd], nformat(%9.2f)
      
      . * replay table
      . collect preview
      
                            |  Obs    Mean   Std. dev.   Min   Max
      ----------------------+-------------------------------------
      Mileage (mpg)         |   74   21.30        5.79    12    41
      Turn circle (ft.)     |   74   39.65        4.40    31    51
      Trunk space (cu. ft.) |   74   13.76        4.28     5    23
      Repair record 1978    |   69    3.41        0.99     1     5
      Car origin            |   74    0.30        0.46     0     1
      Here is the do-file I used to develop this example.
      Code:
      clear all
      
      program custom_summarize
              version 17
              syntax varlist(numeric)         ///
                      [if] [in] [fw aw iw] [, ///
                              name(name)      /// collection name
                              replace         ///
                      ]
      
              * start a new collection
              if "`name'" == "" {
                      * default collection name
                      local name custom_summarize
              }
              if "`name'" == "custom_summarize" {
                      * assume we can always overwrite/replace our default
                      * collection name
                      local replace replace
              }
              collect create `name', `replace'
      
              * custom styles and labels for output
              collect style clear
              * see -help predefined styles-
              collect style use default_halign
              collect style use table_headers
              collect style use default_margins
              collect style use table_nformats
              collect style use default_smcl
              * set borders like -summarize-
              collect style cell border_block[corner row-header], ///
                      nowarn border(right)
              collect style cell border_block[corner column-header], ///
                      nowarn border(bottom)
              * set result labels like -summarize-
              collect label levels result ///
                      count "Obs" ///
                      sd "Std. dev." ///
                      min "Min" ///
                      max "Max"
      
              * compute statistics and report them
              table (var) (result) `if' `in' [`weight'`exp'], ///
                      statistic(count `varlist')              ///
                      statistic(mean `varlist')               ///
                      statistic(sd `varlist')                 ///
                      statistic(min `varlist')                ///
                      statistic(max `varlist')                ///
                      name(`name') append
      end
      
      sysuse auto
      
      summarize mpg turn trunk rep for
      custom_summarize mpg turn trunk rep for
      * change some numeric formats
      collect style cell result[mean sd], nformat(%9.2f)
      * replay table
      collect preview

      Comment


      • #4
        Many thanks Jeff Pitblado (StataCorp) . I have already worked with collect and it is extremely useful. I try to go more in deep into your suggestion.
        Many thanks for your time!

        Comment

        Working...
        X