asdocx : Export Stata Codebook to Word, Excel or LaTeX


asdocx is a Stata package that can export output from almost all Stata commands. This post discusses how to export output from Stata codebook to Word, Excel, LaTeX, or HTML in a compact format. To generate a detailed codebook, see this post . The codebook command examines the variable names, labels, and data to produce a codebook describing the dataset. asdocx can export the output to MS Word, Excel or LaTeX formats. The syntax for the compact codebook is:

asdocx codebook [varlist], replace

In the above code, the [varlist] is optional, therefore, if we leave it out, codebook will be generated for all variables. Instead, if we wanted a codebook for some specific variables, then we would provide list of those variables. Consider the following example, where we want to create a codebook table for mpg, price, and trunk.

asdocx codebook mpg price trunk , replace

 

Export codebook for all variables


Let us create a compact codebook for all variables and send the output to MS Word and then to MS Excel

*Load the working women dataset
sysuse nlsw88, clear

* Send a compact codebook to MS Word
asdocx codebook, replace

And here is the output
asdocx codebook Excel

Since the default output format is MS Word, therefore, we did not use the save() option. If we wanted to send the output to MS Excel, then we must use the save(Myfile.xlsx) option. Myfile can be any valid file name. The extension .xlsx is what asdocx uses to identify the output format.

*Load the working women dataset
sysuse nlsw88, clear

* Send a compact codebook to MS Excel
asdocx codebook, save(Myfile.xlsx) replace

And here is the output
Export codebook from Stata to Word, Excel

Export codebook in HTML format


Codebook can be exported in the html format by using the option save(MyCodeBook.html) where MyCodebook can be any valid file name. All you need is to attach the .html extension to the file.

*Load the working women dataset
 webuse nhanes2b, clear

 * Send a compact codebook to HTML
asdocx codebook, save(MyCodeBook.html) replace
Codebook for https://www.stata-press.com/data/r16/nhanes2b.dta
Var Label name type uniq count mean min max
unique case identifier sampl long 10351 10351 33625.574 1400 64709
stratum identifier, 1-32 stratid byte 31 10351 16.667 1 32
primary sampling unit, 1 or 2 psuid byte 2 10351 1.482 1 2
1=NE, 2=MW, 3=S, 4=W region byte 4 10351 2.581 1 4
1=SMSAcity,2=SMSA~city,4=~SMSA smsa byte 3 10351 2.656 1 4
stand number, 1-64 location byte 62 10351 33.066 1 64
# persons in household, 1-14 houssiz byte 14 10351 2.944 1 14
1=male, 2=female sex byte 2 10351 1.525 1 2
1=white, 2=black, 3=other race byte 3 10351 1.144 1 3
age in years age byte 55 10351 47.580 20 74
height (cm) height float 518 10351 167.651 135.500 200
weight (kg) weight float 745 10351 71.898 30.840 175.880
systolic blood pressure bpsystol int 108 10351 130.882 65 300
diastolic blood pressure bpdiast int 68 10351 81.715 35 150
serum cholesterol (mg/dL) tcresult int 316 10351 217.670 80 828
serum triglycerides (mg/dL) tgresult int 5724 5050 143.896 16 2238
high density lipids (mg/dL) hdresult int 1739 8720 49.643 15 187
hemoglobin (g/dL) hgb float 112 10351 14.260 6.900 20.200
hematocrit (%) hct float 126 10351 41.986 20.200 60.700
total iron bind. cap. (mcg/dL) tibc int 382 10351 366.986 157 792
serum iron (mcg/dL) iron int 229 10351 99.446 16 321
1=excellent,…, 5=poor hlthstat byte 8 10349 2.593 1 8
heart attack, 1=yes, 0=no heartatk byte 4 10349 0.046 0 1
diabetes, 1=yes, 0=no diabetes byte 4 10349 0.048 0 1
1=urban,…, 8=rural sizplace byte 8 10351 5.166 1 8
sampling weight (except lead) finalwgt long 4593 10351 11318.473 2000 79634
sampling weight for lead leadwt long 3262 10351 11283.844 0 81601
mean corpuscular volume (fL) corpuscl float 500 10262 89.967 58.300 125.900
transferrin saturation (%) trnsfern float 590 10351 27.603 3.100 94.300
serum albumin (g/dL) albumin float 363 10016 4.669 3 5.800
serum vitamin C (mg/dL) vitaminc float 426 9973 1.035 0.100 18.100
serum zinc (mcg/dL) zinc int 1271 9202 86.507 43 240
serum copper (mcg/dL) copper int 1466 9131 125.609 37 346
erythrocyte porphyrin (mcg/dl) porphyrn int 243 10270 53.674 20 1307
lead (mcg/dL) lead byte 5456 4948 14.320 2 80
1=female, 0=male female byte 2 10351 0.525 0 1
1 if race=black, 0 otherwise black byte 2 10351 0.105 0 1
1 if race=other, 0 otherwise orace byte 2 10351 0.019 0 1
female heart attack, 1=yes,2=no fhtatk byte 4919 5434 0.029 0 1
# in household or 5 if #>=5 hsizgp byte 5 10351 2.791 1 5
hsizgp== 1.0000 hsiz1 byte 2 10351 0.167 0 1
hsizgp== 2.0000 hsiz2 byte 2 10351 0.351 0 1
hsizgp== 3.0000 hsiz3 byte 2 10351 0.168 0 1
hsizgp== 4.0000 hsiz4 byte 2 10351 0.152 0 1
hsizgp== 5.0000 hsiz5 byte 2 10351 0.162 0 1
region==NE region1 byte 2 10351 0.202 0 1
region==MW region2 byte 2 10351 0.268 0 1
region==S region3 byte 2 10351 0.276 0 1
region==W region4 byte 2 10351 0.254 0 1
smsa== 1.0000 smsa1 byte 2 10351 0.254 0 1
smsa== 2.0000 smsa2 byte 2 10351 0.291 0 1
smsa== 4.0000 smsa3 byte 2 10351 0.455 0 1
1=rural, 0=urban rural byte 2 10351 0.367 0 1
log(lead) loglead float 5456 4948 2.578 0.693 4.382
1 if bpsystol >= 140|bpdiast >= 90, 0 otherwise highbp byte 2 10351 0.423 0 1
Age groups 1-6 agegrp byte 6 10351 3.358 1 6
1 if lead >= 25, 0 otherwise highlead byte 5405 4948 0.059 0 1

 

Order asdocx


Yearly license of asdocx is available at $9.99. Its life-time license is available at $49.99. With the asdocx membership, you get :

  • Life-time license to use
  • All future updates
  • All premium templates / plugins.

 

Order asdocx