Announcement

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

  • renaming table properties and using labels in place of variable names

    I made this table with the code "tabstat x1 x2 x3, statistics( count ) columns(statistics)"

    variable | N
    -------------+----------
    x1 | 1645
    x2 | 1645
    x3 | 1645
    ------------------------

    But I would like that the N column be renamed to a different name such as "Number of People". Also, instead of using the variable names x1, x2, and x3, I would like stata to use the labels instead. the lables are in the data and they are First, second, and third. How do i generate a single code to do that?

    Code:
    * Example generated by -dataex-. To install: ssc install dataex
    clear
    input byte(x1 x2 x3)
    1 1 2
    1 1 2
    1 2 2
    3 3 2
    1 1 2
    2 2 2
    2 2 2
    1 1 2
    1 1 2
    2 2 2
    2 2 2
    2 2 2
    1 1 2
    1 1 2
    1 2 4
    1 1 4
    2 2 4
    2 2 4
    1 1 4
    2 2 4
    end
    ------------------ copy up to and including the previous line ----

  • #2
    This might point you to an improved output, if not exactly what you want.
    Code:
    // set up sample data
    * Example generated by -dataex-. To install: ssc install dataex
    clear
    input byte(x1 x2 x3)
    1 1 2
    1 1 2
    1 2 2
    3 3 2
    1 1 2
    2 2 2
    2 2 2
    1 1 2
    1 1 2
    2 2 2
    2 2 2
    2 2 2
    1 1 2
    1 1 2
    1 2 4
    1 1 4
    2 2 4
    2 2 4
    1 1 4
    2 2 4
    end
    label variable x1 "x1 label"
    label variable x2 "x2 label"
    label variable x3 "x3 label"
    
    // store variable labels
    foreach v of varlist x* {
        local lbl : variable label `v'
        generate str variable`v' = `"`lbl'"'
        }
    // add var_ to the front of each variable name
    rename (x*) (value=)
    // reshape long needs a unique id
    generate id = _n
    list in 1/3, abbreviate(20)
    // reshape long
    reshape long value variable, i(id) j(var) string
    list in 1/9, separator(3) abbreviate(20)
    
    table variable, contents(count id sum value) replace
    rename table1 Count
    rename table2 Sum
    list, clean noobs abbreviate(20)
    Code:
    . list, clean noobs abbreviate(20)
    
        variable   Count   Sum  
        x1 label      20    30  
        x2 label      20    32  
        x3 label      20    52

    Comment


    • #3
      Thank you William Lisowski

      Comment


      • #4
        I am using these to create a table, but I want to rename my columns to column1- robust st.errors, column 2: cluster robust, Instead of FLPR
        (1) (2)
        FLPR FLPR
        FDIIFLOWS_LOG -0.2957*** -0.2957***
        (0.1041) (0.0822)
        GDPGrowth -0.0019 -0.0019
        (0.0240) (0.0247)
        NaturalresourceRent -0.0343 -0.0343
        (0.0327) (0.0259)
        Generalgovernmentexpenditure 0.0422 0.0422
        (0.0587) (0.0376)
        Schoolsecondaryfemale -0.0496 -0.0496**
        (0.0390) (0.0209)
        UrbanPopulationControl 0.0762 0.0762
        (0.1345) (0.0450)
        polity2 -0.1295 -0.1295**
        (0.0787) (0.0606)
        Exports 0.0468 0.0468***
        (0.0356) (0.0122)
        Fertilityrate 0.4640 0.4640
        (0.8038) (0.3152)
        _cons 52.6528*** 52.6528***
        (7.4203) (2.7614)
        N 803 803
        R2 0.154
        The commands I used:

        xtreg FLPR FDIIFLOWS_LOG GDPGrowth NaturalresourceRent Generalgovernmentexpenditure Schoolsecondaryfemale UrbanPopulationControl polity2 Exports Fertilityrate, fe cluster( countrycode)
        eststo
        xtreg FLPR FDIIFLOWS_LOG GDPGrowth NaturalresourceRent Generalgovernmentexpenditure Schoolsecondaryfemale UrbanPopulationControl polity2 Exports Fertilityrate, fe vce(robust)
        eststo
        xtscc FLPR FDIIFLOWS_LOG GDPGrowth NaturalresourceRent Generalgovernmentexpenditure Schoolsecondaryfemale UrbanPopulationControl polity2 Exports Fertilityrate, fe
        eststo
        esttab using myfile21.rtf , star(* .10 ** .05 *** .01) b(4) se r2 nogaps

        Comment

        Working...
        X