Announcement

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

  • Changing order of the variable in table created by "Collect"

    I am wondering how I change the order of the variable in table created by "Collect"
    Here is an example.
    sysuse auto.dta
    collect, tag(model[(1)]): reg price mpg weight
    collect, tag(model[(2)]): reg price foreign weight
    collect dims
    collect levelsof model
    collect layout (colname#result[_r_b]) (model)

    The order of the variables in the table is: mpg weight foreign.
    How do I change the order in the table to: mpg foreign weight?







  • #2
    You can simply spell out the levels of the colname dimension explicitly, in an order you want to display:
    Code:
    collect levelsof colname
    collect layout (colname[mpg foreign weight _cons]#result[_r_b] ) (model)
    Last edited by Evgeny Saburov; 22 Nov 2025, 23:32.

    Comment


    • #3
      Also see

      Code:
      help collect style autolevels
      Code:
      sysuse auto.dta
      collect clear
      collect, tag(model[(1)]): reg price mpg weight
      collect, tag(model[(2)]): reg price foreign weight
      collect layout (colname#result[_r_b]) (model)
      collect style autolevels colname mpg foreign weight _cons
      collect preview
      Res.:

      Code:
      . collect layout (colname#result[_r_b]) (model)
      
      Collection: default
            Rows: colname#result[_r_b]
         Columns: model
         Table 1: 8 x 2
      
      -----------------------------------
                    |       (1)       (2)
      --------------+--------------------
      Mileage (mpg) |                    
        Coefficient | -49.51222          
      Weight (lbs.) |                    
        Coefficient |  1.746559  3.320737
      Car origin    |                    
        Coefficient |            3637.001
      Intercept     |                    
        Coefficient |  1946.069 -4942.844
      -----------------------------------
      
      . 
      . collect style autolevels colname mpg foreign weight _cons
      
      . 
      . collect preview
      
      -----------------------------------
                    |       (1)       (2)
      --------------+--------------------
      Mileage (mpg) |                    
        Coefficient | -49.51222          
      Car origin    |                    
        Coefficient |            3637.001
      Weight (lbs.) |                    
        Coefficient |  1.746559  3.320737
      Intercept     |                    
        Coefficient |  1946.069 -4942.844
      -----------------------------------
      
      .

      Comment


      • #4
        Thank you so much Egenvy and Andrew!

        Comment

        Working...
        X