Announcement

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

  • Masoumeh Sanagou
    started a topic saving results as a matrix

    saving results as a matrix

    Hi Statalist,

    How can I save the results of the following command in a matrix? and how can I export the table after following command to excel using putexcel command?

    Code:
    table group SurveyYear , content(mean median_CTDI mean median_DLP)




  • Red Owl
    replied
    Sorry, I left out the -by()- option, which I believe would do what you want. Unfortunately, the -by()- option in -tabstat- only works for a single grouping var, so the solution is slightly more complicated.

    Perhaps the following approach will work for you.
    Code:
    sysuse auto, clear
    
    * Create two categorical variables for the demo.
    gen str3 catvar1 = "Dom"
    replace catvar1 = "For" if foreign
    gen catvar2 = "Group1"
    replace catvar2 = "Group2" if rep78 >3
    
    tabstat price mpg, stat(mean median) by(catvar1) save
    
    mat A1 = r(Stat1)
    mat A2 = r(Stat2)
    
    tabstat price mpg, stat(mean median) by(catvar2) save
    
    mat B1 = r(Stat1)
    mat B2 = r(Stat2)
    
    mat C = A1,A2\B1,B2
    
    matlist C
    Hope that helps.

    Red Owl
    Stata/IC 15.1, Windows 10 (64-bit)

    Leave a comment:


  • Masoumeh Sanagou
    replied
    Thanks for the reply.

    group and SurveyYear are categorical variables and the result of
    Code:
    table group SurveyYear
    and
    Code:
    tabstat group SurveyYear
    are different.

    Unfortunately, tabstat does not give me the table that I wanted.

    Leave a comment:


  • Red Owl
    replied
    Here's an example of what I might use:
    Code:
    sysuse auto, clear
    
    tabstat price mpg, stat(mean median) save
    
    matrix list r(StatTotal)
    You can then -putexcel- the matrix r(StatTotal) into Excel.

    Red Owl
    Stata/IC 15.1, Windows 10 (64-bit)

    Leave a comment:

Working...
X