Announcement

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

  • Collect style commands - abbreviating statistic names

    Is there a way in Stata 17+ to establish some kind of style setting such that statistic names can be abbreviated? For example, the command below shows the default behavior of the table command, which displays the full name of each statistic (i.e., "Mean", "Standard Deviation"). I would like to set a custom style wherein such statistic names always/permanently are abbreviated. I can't seem to accomplish this using table options or the collect style suite of commands, so I'm beginning to think it isn't possible except on a table-by-table basis using the collect label levels result approach.


    Code:
    . sysuse auto2, clear
    (1978 automobile data)
    
    . table foreign rep78, stat(mean price) stat(sd price)
    
    ------------------------------------------------------------------------------------------
                           |                         Repair record 1978                       
                           |      Poor       Fair    Average       Good   Excellent      Total
    -----------------------+------------------------------------------------------------------
    Car origin             |                                                                  
      Domestic             |                                                                  
        Mean               |    4564.5   5967.625   6607.074   5881.556      4204.5    6179.25
        Standard deviation |  522.5519   3579.357   3661.267   1592.019    311.8341   3188.969
      Foreign              |                                                                  
        Mean               |                        4828.667   6261.444    6292.667   6070.143
        Standard deviation |                        1285.613   1896.092    2765.629   2220.984
      Total                |                                                                  
        Mean               |    4564.5   5967.625   6429.233     6071.5        5913   6146.043
        Standard deviation |  522.5519   3579.357    3525.14   1709.608    2615.763    2912.44
    ------------------------------------------------------------------------------------------














  • #2

    There are two ways of accomplishing this.

    1. Create a file with your custom labels that you reference with option label() each time you use table.

    2. Create a file you can set collect_label with option permanently.


    -----------------------------------------------------------------------------
    Details for 1:

    You might end up doing this more than once, so I would use a a do-file.

    Create an empty collection where you assign labels to each statistic() level of the result dimension supported by command table. Use collect label save to save these result labels to disk, then place the resulting file in your PERSONAL folder so that Stata has access to it via the adopath.

    Specify this file in option label() when you use table, or collect label use it with option modify after your call to table.

    Here is a toy example:
    Code:
    collect clear
    collect label levels result ///
        mean "Avg." ///
        sd "Std. dev." ///
        min "Min." ///
        max "Max."
    collect label save `"mytablabs"', replace
    
    sysuse auto2
    table foreign rep78, stat(mean price) stat(sd price) label(mytablabs)
    table foreign rep78, stat(mean price) stat(sd price)
    collect label use mytablabs, modify
    collect preview

    -----------------------------------------------------------------------------
    Details for 2:

    Copy file label-default.stjson to your PERSONAL folder, but change defult to something else, like label-mydefault.stjson. The content of this file will be
    Code:
    {
      "LabelIncludes": [
        "dimension",
        "result"
      ]
    }
    Change your copy by adding another element after "result", something like
    Code:
    {
      "LabelIncludes": [
        "dimension",
        "result",
        "mytable"
      ]
    }
    Next, in PERSONAL, create a new file named label-mytable.stjson and here you will define your custom labels for table's statistics. Here is the layout of this file, to get you started, change the labels as you see fit.
    Code:
    {
      "Labels": {
        "Results": {
          "count": {
            "table": "Number of nonmissing values"
          },
          "cv": {
            "table": "Coefficient of variation"
          },
          "first": {
            "table": "First value"
          },
          "firstnm": {
            "table": "First nonmissing value"
          },
          "frequency": {
            "table": "Frequency"
          },
          "fvfrequency": {
            "table": "Factor-variable frequency"
          },
          "fvpercent": {
            "table": "Factor-variable percent"
          },
          "fvproportion": {
            "table": "Factor-variable proportion"
          },
          "fvrawfrequency": {
            "table": "Unweighted factor-variable frequency"
          },
          "fvrawpercent": {
            "table": "Unweighted factor-variable percent"
          },
          "fvrawproportion": {
            "table": "Unweighted factor-variable proportion"
          },
          "geomean": {
            "table": "Geometric mean"
          },
          "geosd": {
            "table": "Geometric standard deviation"
          },
          "iqr": {
            "table": "Interquartile range"
          },
          "kurtosis": {
            "table": "Kurtosis"
          },
          "last": {
            "table": "Last value"
          },
          "lastnm": {
            "table": "Last nonmissing value"
          },
          "max": {
            "table": "Maximum value"
          },
          "mean": {
            "table": "Mean"
          },
          "median": {
            "table": "Median"
          },
          "min": {
            "table": "Minimum value"
          },
          "percent": {
            "table": "Percent"
          },
          "percentile": {
            "table": "Percentile"
          },
          "proportion": {
            "table": "Proportion"
          },
          "q1": {
            "table": "First quartile"
          },
          "q2": {
            "table": "Second quartile"
          },
          "q3": {
            "table": "Third quartile"
          },
          "range": {
            "table": "Range"
          },
          "rawpercent": {
            "table": "Unweighted percent"
          },
          "rawproportion": {
            "table": "Unweighted proportion"
          },
          "rawtotal": {
            "table": "Unweighted total"
          },
          "sd": {
            "table": "Standard deviation"
          },
          "sebinomial": {
            "table": "Standard error of the mean, binomial"
          },
          "semean": {
            "table": "Standard error of the mean"
          },
          "sepoisson": {
            "table": "Standard error of the mean, Poisson"
          },
          "skewness": {
            "table": "Skewness"
          },
          "stars": {
            "table": "Stars"
          },
          "sumw": {
            "table": "Sum of weights"
          },
          "sumw4var": {
            "table": "Sum of weights for variable"
          },
          "svycv": {
            "table": "Coefficient of variation (svy)"
          },
          "total": {
            "table": "Total"
          },
          "variance": {
            "table": "Variance"
          }
        }
      }
    }
    In Stata type,
    Code:
    set collect_label mydefault, permanently
    Moving forward, table should pick your labels.

    Comment


    • #3
      Thanks Jeff. I'll give that a try. Can you elaborate on what you mean by my "PERSONAL" folder?

      Comment


      • #4
        See help adopath.

        Comment


        • #5
          I tried option #2 and it worked perfectly. Thanks Jeff!

          Comment

          Working...
          X