Announcement

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

  • Exporting summary tables to Excel or word

    Hi there,

    I have written a foreach loop to get the three different tables and I want to export the results into excel or word. My code is:


    clear all
    set more off
    use "R:\CIHI data\Drug shortage\2018\Sasdata\daily_S_D_20180725.dta"
    append using "R:\CIHI data\Drug shortage\2018\Sasdata\daily_Other_20180725.dta"
    keep if existing==1

    foreach x of varlist market_aig_route_form2 market_ai_route_form2 market_ai {
    bysort date `x' : egen n_DINdate_market1= count (din_pdin)
    bysort date `x' : egen n_shortagedate_market1= sum (sd)

    gen n_DIN_shortage=1 if n_DINdate_market1==n_shortagedate_market1
    keep if n_DIN_shortage==1


    duplicates drop `x' n_DINdate_market1, force
    bysort n_DINdate_market1: egen n_market= count (`x')
    //rename _freq _freq1
    duplicates drop n_market n_DINdate_market1, force
    sort n_DINdate_market1

    tab2xl n_market n_DINdate_market1 using results, row(1) col(1)

    }

    My question is that how can I get the result in the excel for each loop? I tried tab2xl command but it does not turn into a desired result I want and for each loop either

    I would appreciate your help and many thanks for the useful website

    Aida

  • #2
    First of all, this forum is dedicated to discussions related to Mata, your question is more related to Stata.
    Second, I have not fully understood what you really want to export. Is it the data set or some results from Stata commands. My guess is that you want to export some variables from the data set. If so, you can use asdoc to export variables from your data set to a MS word table. In the following example, I am using the sub-command list of asdoc.

    Code:
    * To install asdoc
    ssc install asdoc
    
    * Use the auto dataset for our example
    sysuse auto
    
    * Export values of variables make price trunk mpg and turn for first 10 observations
      asdoc list make price trunk mpg turn in 1/10 , replace
    And here is the output
    Click image for larger version

Name:	asdoc list.png
Views:	1
Size:	25.9 KB
ID:	1462652
    Regards
    --------------------------------------------------
    Attaullah Shah, PhD.
    Professor of Finance, Institute of Management Sciences Peshawar, Pakistan
    FinTechProfessor.com
    https://asdocx.com
    Check out my asdoc program, which sends outputs to MS Word.
    For more flexibility, consider using asdocx which can send Stata outputs to MS Word, Excel, LaTeX, or HTML.

    Comment

    Working...
    X