|
2 | 2 | Purpose: Exporting tabulations to excel |
3 | 3 | Data input: The model dataset women's file (IR file) |
4 | 4 | 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 |
6 | 6 |
|
7 | 7 | Notes/Instructions: |
8 | 8 |
|
@@ -33,20 +33,33 @@ label var modfp "currently use a modern method" |
33 | 33 | * install tabout program if it is not installed already |
34 | 34 | ssc install tabout |
35 | 35 |
|
36 | | -* One way tabulation (tabulate one variable at a time) |
| 36 | +**** One way tabulation (tabulate one variable at a time) **** |
| 37 | + |
37 | 38 | * note the use of "oneway" since this is a one way tabulations |
38 | 39 | * the svy command and wt are also included |
39 | 40 | tabout v106 v025 v024 using table1.xls, c(cell) oneway svy nwt(wt) per pop replace |
40 | 41 |
|
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 | + |
42 | 53 | * example: tabulate modern contraceptive methhod use by education, residence, and region |
43 | 54 | * the last variale on the list should be the outcome variable |
44 | 55 | * note that we use c(row ci) to indicate we want row percentages and the confidence interval |
45 | 56 | * there is also the stats(chi2) option to produce the chi-square test results |
46 | 57 | tabout v106 v025 v024 modfp using table2.xls if v502==1, c(row ci) stats(chi2) svy nwt(wt) per pop replace |
47 | 58 |
|
| 59 | +****************************************************************************** |
48 | 60 |
|
49 | 61 | *** Using putexcel command *** |
| 62 | + |
50 | 63 | * using tabout can require a lot of copy and pasting to produce a table for a report or paper. |
51 | 64 | * using putexcel can help produce a table that is closer to what would appear as a final table. |
52 | 65 | * 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 { |
165 | 178 | local prow = `row' -1 |
166 | 179 | } |
167 | 180 |
|
168 | | - |
| 181 | +****************************************************************************** |
0 commit comments