Announcement

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

  • Table with horizontal line above the total

    Using table and collect not very often I am struggling with the collect commands.

    I am using
    Code:
    clear
    * Example generated by -dataex-. For more info, type help dataex
    clear
    input float grade_st byte age
    14 13
    14 14
    14 15
    14 14
    16 16
    14 14
    15 16
    15 15
    14 14
    14 14
    14 14
    15 15
    15 15
    16 16
    14 13
    15 15
    14 14
    15 15
    14 14
    16 16
    14 14
    13 13
    16 16
    13 13
    14 15
    13 14
    15 15
    16 16
    15 15
    13 14
    16 16
    16 17
    17 19
    15 15
    13 13
    16 18
    14 .a
    14 14
    14 15
    16 16
    15 16
    16 17
    15 15
    15 .a
    18 16
    18 18
    16 16
    15 15
    17 17
    14 14
    14 13
    16 16
    13 13
    15 14
    15 14
    17 18
    14 14
    13 13
    17 17
    16 16
    13 13
    15 14
    13 13
    end
    label values age age
    label def age .a "no answer", modify
    
    qui table grade_st, statistic(n age) statistic(mean age) statistic(sd age) ///
        statistic(min age) statistic(max age)
    collect label levels result count "Obs" mean "Mean" sd "Std. dev." ///
        min "Min" max "Max", modify
    collect style cell result[mean sd], nformat(%4.1f)
    collect style cell result[count min max], nformat(%6.0fc)
    collect preview
    amd get
    Code:
    . collect preview
    
    ----------------------------------------------
             |  Obs   Mean   Std. dev.   Min   Max
    ---------+------------------------------------
    grade_st |                                    
      13     |    9   13.2         0.4    13    14
      14     |   18   14.0         0.6    13    15
      15     |   15   14.9         0.6    14    16
      16     |   13   16.3         0.6    16    18
      17     |    4   17.8         1.0    17    19
      18     |    2   17.0         1.4    16    18
      Total  |   61   15.0         1.5    13    19
    ----------------------------------------------
    How to get a horizontal line above the Total?

  • #2
    See highlighted below. You want to reference the row dimension and the total level, which usually takes the value ".m".

    Code:
    clear
    * Example generated by -dataex-. For more info, type help dataex
    clear
    input float grade_st byte age
    14 13
    14 14
    14 15
    14 14
    16 16
    14 14
    15 16
    15 15
    14 14
    14 14
    14 14
    15 15
    15 15
    16 16
    14 13
    15 15
    14 14
    15 15
    14 14
    16 16
    14 14
    13 13
    16 16
    13 13
    14 15
    13 14
    15 15
    16 16
    15 15
    13 14
    16 16
    16 17
    17 19
    15 15
    13 13
    16 18
    14 .a
    14 14
    14 15
    16 16
    15 16
    16 17
    15 15
    15 .a
    18 16
    18 18
    16 16
    15 15
    17 17
    14 14
    14 13
    16 16
    13 13
    15 14
    15 14
    17 18
    14 14
    13 13
    17 17
    16 16
    13 13
    15 14
    13 13
    end
    label values age age
    label def age .a "no answer", modify
    
    qui table grade_st, statistic(n age) statistic(mean age) statistic(sd age) ///
        statistic(min age) statistic(max age)
    collect label levels result count "Obs" mean "Mean" sd "Std. dev." ///
        min "Min" max "Max", modify
    collect style cell result[mean sd], nformat(%4.1f)
    collect style cell result[count min max], nformat(%6.0fc)
    collect style cell grade_st[.m], border(top)
    collect preview
    Res.:

    Code:
    . collect style cell grade_st[.m], border(top)
    
    . collect preview
    
    ----------------------------------------------
             |  Obs   Mean   Std. dev.   Min   Max
    ---------+------------------------------------
    grade_st |                                    
      13     |    9   13.2         0.4    13    14
      14     |   18   14.0         0.6    13    15
      15     |   15   14.9         0.6    14    16
      16     |   13   16.3         0.6    16    18
      17     |    4   17.8         1.0    17    19
      18     |    2   17.0         1.4    16    18
    ---------+------------------------------------
      Total  |   61   15.0         1.5    13    19
    ----------------------------------------------

    Comment


    • #3
      Thanks a lot for your perfect and extremely fast assistance!

      Comment

      Working...
      X