Announcement

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

  • Simplest way to permanently change result level labels of "Factor-variable frequency" and " Factor-variable percent" for table command

    I would prefer to replace these with something shorter like "N" and "%" permanently. Currently I am working harder and stupider by running a collect label levels command after the table command.
    Thanks

  • #2
    You can save relevant style commands into a style file, that you can then call up to apply to your current collection. See -help collect style save- for details and examples.

    Comment


    • #3
      collect provides command-specific result labels, but you can define your own, save them to a file, and use option label() or command collect label use to override the defaults.

      Here is an example using table and the auto data.
      Code:
      sysuse auto
      
      * clear all collections from memory
      collect clear
      * define your result labels
      collect label levels result ///
          fvfrequency "N" ///
          fvpercent "%" ///
          , modify
      * save your labels to a file
      collect label save myfvlabels, replace
      
      * specify your result labels file in option -label()-
      table (var) (result), ///
          statistic(fvfrequency for rep) ///
          statistic(fvpercent for rep) ///
          label(myfvlabels)
      Here is the resulting table.
      Code:
      ----------------------------------
                           |   N       %
      ---------------------+------------
      Car origin=Domestic  |  52   70.27
      Car origin=Foreign   |  22   29.73
      Repair record 1978=1 |   2    2.90
      Repair record 1978=2 |   8   11.59
      Repair record 1978=3 |  30   43.48
      Repair record 1978=4 |  18   26.09
      Repair record 1978=5 |  11   15.94
      ----------------------------------


      It is also possible to override the default result labels if you are willing to edit some JSON files. If you look at the documentation for set collect_label you will find that your ado-path contains a file named label-default.stjson. Its contents look like
      Code:
      {
        "LabelIncludes": [
          "dimension",
          "result"
        ]
      }
      Make a copy of this file, with a different name than default and put it in your PERSONAL folder. For example, name the copy label-mydefault.stjson, and edit it to include your default result labels, something like
      Code:
      {
        "LabelIncludes": [
          "dimension",
          "result",
          "myresult"
        ]
      }
      Now find the file label-result.stjson in your ado-path, and copy that to your PERSONAL folder with the name label-myresult.stjson. Edit the labels in your myresult labels file. I trimmed the file down to just the command-specific result labels I want to change, so my label-myresult.stjson looks like
      Code:
      {
        "Labels": {
          "Results": {
            "fvfrequency": {
              "table": "N"
            },
            "fvpercent": {
              "table": "%"
            },
            "fvproportion": {
              "table": "Proportion"
            },
            "fvrawfrequency": {
              "table": "N (unweighted)"
            },
            "fvrawpercent": {
              "table": "% (unweighted)"
            },
            "fvrawproportion": {
              "table": "Proportion (unweighted)"
            }
          }
        }
      }
      Finally, make Stata use the mydefault labels and test it out with the table command.
      Code:
      set collect_label mydefault
      
      table (var) (result), ///
          statistic(fvfrequency for rep) ///
          statistic(fvpercent for rep)
      Assuming this works for you, you can make this permanent by adding option permanently in your call to set collect_label.

      Comment

      Working...
      X