Skip to content

Commit 7fc46db

Browse files
committed
Update ExportingTabs.do
1 parent c8752c3 commit 7fc46db

File tree

1 file changed

+17
-4
lines changed

1 file changed

+17
-4
lines changed

Intro_DHSdata_Analysis/3_Exporting_Tabulations/ExportingTabs.do

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
Purpose: Exporting tabulations to excel
33
Data input: The model dataset women's file (IR file)
44
Author: Shireen Assaf
5-
Date Last Modified: Feb 1, 2023 by Shireen Assaf
5+
Date Last Modified: Aug 4, 2023 by Shireen Assaf to add dtable option for Stata 18 users
66
77
Notes/Instructions:
88
@@ -33,20 +33,33 @@ label var modfp "currently use a modern method"
3333
* install tabout program if it is not installed already
3434
ssc install tabout
3535

36-
* One way tabulation (tabulate one variable at a time)
36+
**** One way tabulation (tabulate one variable at a time) ****
37+
3738
* note the use of "oneway" since this is a one way tabulations
3839
* the svy command and wt are also included
3940
tabout v106 v025 v024 using table1.xls, c(cell) oneway svy nwt(wt) per pop replace
4041

41-
* two-way tabulation: tabulate one variable with the outcome one at a time
42+
* If you have Stata 18, you can also use the dtable command for one way tabulations.
43+
* See below for exmaple code that would give the same output as the oneway tabout above.
44+
dtable i.v106 i.v025 i.v024, svy nformat(%9.1f mean) nosample column(summary(N / %)) title(Table 1) export(table1b.docx)
45+
46+
* you can also export as an excel file by using export(Table.xlsx) in dtable code above
47+
48+
* In both the tabout and dtable oneway tabulations above, you don't need to use svy and can just apply weights using [iw=wt] since you are not reporting SE or confidence intervals. However, using svy will also be correct.
49+
50+
51+
**** Two-way tabulation: tabulate one variable with the outcome one at a time ****
52+
4253
* example: tabulate modern contraceptive methhod use by education, residence, and region
4354
* the last variale on the list should be the outcome variable
4455
* note that we use c(row ci) to indicate we want row percentages and the confidence interval
4556
* there is also the stats(chi2) option to produce the chi-square test results
4657
tabout v106 v025 v024 modfp using table2.xls if v502==1, c(row ci) stats(chi2) svy nwt(wt) per pop replace
4758

59+
******************************************************************************
4860

4961
*** Using putexcel command ***
62+
5063
* using tabout can require a lot of copy and pasting to produce a table for a report or paper.
5164
* using putexcel can help produce a table that is closer to what would appear as a final table.
5265
* the code below describes how putexcel can be used for creating a crosstabulation of one indicator with several background variables.
@@ -165,4 +178,4 @@ foreach y in tot v106 v025 v024 {
165178
local prow = `row' -1
166179
}
167180

168-
181+
******************************************************************************

0 commit comments

Comments
 (0)