asdocx: Export from Stata to Word, Excel, LaTeX & HTML Forums asdocx Forum asdocx: export tables from Gtools – Gstats tab | Stata

Tagged: ,

Viewing 3 posts - 1 through 3 (of 3 total)
  • Author
    Posts
  • Ozer Erdem
    Participant
    Post count: 14

    Hi Dr. Shah,

    I am trying to get gstats tab results into asdocx.
    https://gtools.readthedocs.io/en/latest/usage/gstats_summarize/

    It is giving me the option to save the results in Mata. Unfortunately, it does not have an matrix output/table.
    It is very fast compared to tabstat. Therefore, I would like to use it and save the results with asdocx.

    sysuse auto, clear
    gstats tab price mpg, by(rep78)   noprint matasave(StatsByRep)
    
    mata StatsByRep.desc()
    mata StatsByForeign.desc()
    mata StatsByForeign.printOutput()

    Can I learn how I can get this table into asdocx?
    Thank you.

    Attaullah Shah
    Moderator
    Post count: 76

    Here is something you can work with. I tried to find the colvector for variable names, but did not find. But I was in hurry, you may find it somewhere in the gtools documentations.

    sysuse auto, clear
    gstats tab price mpg, by(foreign strvar) matasave
    
    * Get the statistics matrix from the GstatsOutput class
    * Note: We need to convert the real matrix to string first
    mata stat_values = strofreal(GstatsOutput.output)
    
    * Get the names of the statistics
    mata stat_names = GstatsOutput.statnames
    
    * Combine the two matrices
    mata outtable = stat_names \ stat_values
    
    * Add the matrix to asdocx system
    flexmat reset
    flexmat addmat, matname(outtable) 
    
    * Export to word
    asdocx export
    
      0 |1            2             3          4          5             6 
    ----+------------------------------------------------------------------
      1 |n          sum          mean        min        max            sd 
    ----+------------------------------------------------------------------
      2 |4        19162        4790.5       3799       6486      1169.903 
      3 |4           93         23.25         19         26       3.40343 
      4 |2         9129        4564.5       4195       4934      522.5519 
      5 |2           42            21         18         24      4.242641 
      6 |8        47741      5967.625       3667      14500      3579.357 
      7 |8          153        19.125         14         24      3.758324 
      8 |27      178391      6607.074       3291      15906      3661.267 
      9 |27         513            19         12         29      4.085622 
     10 |9        52934      5881.556       3829       8814      1592.019 
     11 |9          166      18.44444         14         28      4.585605 
     12 |2         8409        4204.5       3984       4425      311.8341 
     13 |2           64            32         30         34      2.828427 
     14 |1        12990         12990      12990      12990             . 
     15 |1           14            14         14         14             . 
     16 |3        14486      4828.667       3895       6295      1285.613 
     17 |3           70      23.33333         21         26      2.516611 
     18 |9        56353      6261.444       3995       9735      1896.092 
     19 |9          224      24.88889         21         30      2.713137 
     20 |9        56634      6292.667       3748      11995      2765.629 
     21 |9          237      26.33333         17         41      9.367497 
    -----------------------------------------------------------------------
    
    Ozer Erdem
    Participant
    Post count: 14

    Looks great.
    Thank you.

Viewing 3 posts - 1 through 3 (of 3 total)
  • You must be logged in to reply to this topic.