Announcement

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

  • complete column names (tab)

    Dear All, I found this question here. The data /code is:
    Code:
    * Example generated by -dataex-. To install: ssc install dataex
    clear
    input str16 var1 str7 var2
    "测试长字符1" "地区1"
    "测试长字符2" "地区1"
    "测试长字符1" "地区1"
    "测试长字符1" "地区1"
    "测试长字符2" "地区2"
    "测试长字符1" "地区1"
    "测试长字符2" "地区2"
    "测试长字符3" "地区2"
    end
    
    tab var2 var1
    The outcome is:
    Code:
    . tab var2 var1
    
               |               var1
          var2 |  测试长..   测试长..   测试长.. |     Total
    -----------+---------------------------------+----------
         地区1 |         4          1          0 |         5 
         地区2 |         0          2          1 |         3 
    -----------+---------------------------------+----------
         Total |         4          3          1 |         8
    The question is: How can we make the column names [测试长.. 测试长.. 测试长..] complete? Thanks.
    Ho-Chuan (River) Huang
    Stata 19.0, MP(4)

  • #2
    If you have Stata 17 then table (var2) (var1) would be a possible sollution
    ---------------------------------
    Maarten L. Buis
    University of Konstanz
    Department of history and sociology
    box 40
    78457 Konstanz
    Germany
    http://www.maartenbuis.nl
    ---------------------------------

    Comment


    • #3
      Dear Maarten, Thanks for this suggestion. Indeed, I have Stata 17 version:
      Click image for larger version

Name:	_20220721164824.jpg
Views:	1
Size:	6.4 KB
ID:	1674395

      However, I wonder if there is another solution if one doesn't have Stata 17. Thanks.

      Ho-Chuan (River) Huang
      Stata 19.0, MP(4)

      Comment


      • #4
        Code:
        ssc install estout, replace

        Code:
        * Example generated by -dataex-. For more info, type help dataex
        clear
        input str16 var1 str7 var2
        "测试长字符1" "地区1"
        "测试长字符2" "地区1"
        "测试长字符1" "地区1"
        "测试长字符1" "地区1"
        "测试长字符2" "地区2"
        "测试长字符1" "地区1"
        "测试长字符2" "地区2"
        "测试长字符3" "地区2"
        end
        
        qui estpost tab var2 var1
        esttab, cell(b(fmt(0))) unstack nonum collab(none) noobs modelwidth(15) ///
        varlabels(`e(labels)') eqlabels(`e(eqlabels)', lhs("`e(rowvar)'")) mtitle("`e(colvar)'")
        Res.:

        Code:
        . esttab, cell(b(fmt(0))) unstack nonum collab(none) noobs modelwidth(15) ///
        > varlabels(`e(labels)') eqlabels(`e(eqlabels)', lhs("`e(rowvar)'")) mtitle("`e(colvar)'")
        
        ----------------------------------------------------------------------------
                                var1                                                
        var2             测试长字符1     测试长字符2     测试长字符3           Total
        ----------------------------------------------------------------------------
        地区1                      4               1               0               5
        地区2                      0               2               1               3
        Total                      4               3               1               8
        ----------------------------------------------------------------------------
        Last edited by Andrew Musau; 21 Jul 2022, 03:25.

        Comment


        • #5
          Code:
          table var2 var1, col row mi

          Comment


          • #6
            Dear @Andrew Musau and @Romalpa Akzo, Many thanks for these helpful suggestions.

            Ho-Chuan (River) Huang
            Stata 19.0, MP(4)

            Comment

            Working...
            X