Announcement

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

  • Table from string and numeric variables

    Hello,
    this is a general question about the best approach. I am using stata 16.1

    I want to make a table from one string variable and several numeric variables for e.g. the first 50 observations (showing single observations not summary statistics). I want to use the string variable as row labels. There should be many customization options.
    I have tried several approaches but neither seems optimal.

    The list command does in principle what I want to do but with very limited customization options. I want to use variable labels instead for the variable names, different formats and column width for the numeric variables. If possible customized placement of separating lines would be nice (customization a little bit like in Excel).
    I came closest by using matrices but labeling the row names is challenging and the maximum length of the label expression is limited (as I understand it).

    Which approach would you suggest?
    Thanks!

  • #2
    As you say, list springs to mind. But it's hard to know what to make of all your other ideals. Different formats are fine, as list just uses the assigned format. You can get list to show variable labels as headers, but that conflicts mightily with any desire to reduce column width.

    Here's some technique:

    Code:
    sysuse auto
    
    foreach v in mpg weight price {
        char `v'[varname] "`: var label `v''"
    }
    l
    list mpg weight price in 1/10, subvarname abbrev(20)
    
         +----------------------------------------+
         | Mileage (mpg)   Weight (lbs.)    Price |
         |----------------------------------------|
      1. |            22           2,930    4,099 |
      2. |            17           3,350    4,749 |
      3. |            22           2,640    3,799 |
      4. |            20           3,250    4,816 |
      5. |            15           4,080    7,827 |
         |----------------------------------------|
      6. |            18           3,670    5,788 |
      7. |            26           2,230    4,453 |
      8. |            20           3,280    5,189 |
      9. |            16           3,880   10,372 |
     10. |            19           3,400    4,082 |
         +----------------------------------------+
    Code:
    
    

    Comment


    • #3
      Thanks Nick for your fast reply and nice trick for labeling. It is getting close to what I was thinking about!
      Overall, I feel now that probably the best way to get my desired result is using export options like putexcel or asdoc.

      Comment

      Working...
      X