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
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
Comment