├── .github └── workflows │ └── jekyll-gh-pages.yml ├── .gitignore ├── LICENSE ├── Library ├── Master.do ├── ado │ ├── README.md │ ├── chartable.ado │ ├── chartable.sthlp │ ├── chartablesheet.ado │ ├── custombar.ado │ ├── custombar.sthlp │ ├── freeshape.ado │ ├── freeshape.sthlp │ ├── labelcollapse.ado │ ├── labelcollapse.sthlp │ ├── reftab.ado │ ├── reftab.sthlp │ ├── tabgen.ado │ ├── tabgen.sthlp │ ├── tabstatout.ado │ ├── tabstatout.sthlp │ ├── weightab.ado │ └── weightab.sthlp ├── bar-better-ci.html ├── bar-better.html ├── bar-betterbar.html ├── bar-over.html ├── bar-stack-by.html ├── bar-stack-cat.html ├── bar-two-axes.html ├── bar-weightab.html ├── binned-scatter.html ├── boxplot-pctile.html ├── confidence-intervals.html ├── content-summary.csv ├── data │ ├── README.md │ ├── bar-better-ci.dta │ ├── bar-better.dta │ ├── bar-counts.dta │ ├── bar-custombar.dta │ ├── bar-over.dta │ ├── bar-stack-by.dta │ ├── bar-stack-cat.dta │ ├── bar-two-axes.dta │ ├── bar-weightab.dta │ ├── binned-scatter.dta │ ├── boxplot-pctile.dta │ ├── confidence-intervals.dta │ ├── density-av.dta │ ├── density-data.dta │ ├── density-shaded.dta │ ├── density-shaded.dta.dta │ ├── dot-summary.dta │ ├── eventstudy-prepost.dta │ ├── line-fit-text.dta │ ├── reg-chartable.dta │ ├── reg-models.dta │ ├── reg-panels.dta │ ├── regression-fit.dta │ ├── scatter-fl-ci.dta │ ├── scatter-fl.dta │ ├── scatter-poly-ci.dta │ └── scatter-strata.dta ├── density-av.html ├── density-data.html ├── density-shaded.html ├── do │ ├── bar-better-ci.do │ ├── bar-better.do │ ├── bar-betterbar.do │ ├── bar-counts.do │ ├── bar-custombar.do │ ├── bar-over.do │ ├── bar-sorted.do │ ├── bar-stack-by.do │ ├── bar-stack-cat.do │ ├── bar-two-axes.do │ ├── bar-weightab.do │ ├── binned-scatter.do │ ├── boxplot-pctile.do │ ├── confidence-intervals.do │ ├── density-av.do │ ├── density-data.do │ ├── density-shaded.do │ ├── dot-summary.do │ ├── eventstudy-prepost.do │ ├── line-fit-text.do │ ├── line-plottig.do │ ├── line-uncluttered.do │ ├── map-world.do │ ├── reg-chartable.do │ ├── reg-het.do │ ├── reg-models.do │ ├── reg-predicted.do │ ├── regression-fit.do │ ├── scatter-fl-ci.do │ ├── scatter-fl.do │ ├── scatter-poly-ci.do │ ├── scatter-strata.do │ └── scatter-transparent.do ├── dot-summary.html ├── eventstudy-prepost.html ├── line-fit-text.html ├── line-plottig.html ├── line-uncluttered.html ├── map-world.html ├── reg-chartable.html ├── reg-het.html ├── reg-models.html ├── reg-predicted.html ├── scatter-fl-ci.html ├── scatter-fl.html ├── scatter-poly-ci.html ├── scatter-strata.html ├── scatter-transparent.html ├── template-category-page.do └── template-plot-page.do ├── README.md └── docs ├── BarPlots.html ├── BoxPlots.html ├── Contribute.html ├── DensityPlots.html ├── EventStudy.html ├── LinePlots.html ├── Links.html ├── Map.html ├── Maps.html ├── RegressionCoef.html ├── ScatterPlots.html ├── bar-better-ci.html ├── bar-better.html ├── bar-betterbar.html ├── bar-over.html ├── bar-stack-by.html ├── bar-stack-cat.html ├── bar-two-axes.html ├── bar-weightab.html ├── binned-scatter.html ├── boxplot-pctile.html ├── confidence-intervals.html ├── density-av.html ├── density-data.html ├── density-shaded.html ├── dot-summary.html ├── eventstudy-prepost.html ├── figure ├── bar-better-ci.png ├── bar-better.png ├── bar-betterbar.png ├── bar-counts.png ├── bar-custombar.png ├── bar-over.png ├── bar-stack-by.png ├── bar-stack-cat.png ├── bar-two-axes.png ├── bar-weightab.png ├── binned-scatter.png ├── boxplot-pctile.png ├── cheatsheet.PNG ├── confidence-intervals.png ├── density-av.png ├── density-data.png ├── density-shaded.png ├── dimewiki.PNG ├── dot-summary.png ├── drip.PNG ├── eventstudy-prepost.png ├── grstyle.PNG ├── iefieldkit.PNG ├── ietoolkit.PNG ├── line-fit-text.png ├── line-plottig.png ├── line-uncluttered.png ├── map-world.png ├── official.PNG ├── practices.PNG ├── r.PNG ├── rd.png ├── reg-chartable.png ├── reg-het.png ├── reg-models.png ├── reg-predicted.png ├── regression-fit.png ├── scatter-fl-ci.png ├── scatter-fl.png ├── scatter-poly-ci.png ├── scatter-strata.png ├── scatter-transparent.png ├── sdas.PNG └── visual-overview.PNG ├── header.html ├── index.html ├── line-fit-text.html ├── line-plottig.html ├── line-uncluttered.html ├── map-world.html ├── reg-chartable.html ├── reg-het.html ├── reg-models.html ├── reg-predicted.html ├── scatter-fl-ci.html ├── scatter-fl.html ├── scatter-poly-ci.html ├── scatter-strata.html ├── scatter-transparent.html └── site_libs ├── bootstrap-3.3.5 ├── css │ ├── bootstrap-theme.css │ ├── bootstrap-theme.css.map │ ├── bootstrap-theme.min.css │ ├── bootstrap.css │ ├── bootstrap.css.map │ ├── bootstrap.min.css │ ├── cerulean.min.css │ ├── cosmo.min.css │ ├── darkly.min.css │ ├── flatly.min.css │ ├── fonts │ │ ├── Lato.ttf │ │ ├── LatoBold.ttf │ │ ├── LatoItalic.ttf │ │ ├── NewsCycle.ttf │ │ ├── NewsCycleBold.ttf │ │ ├── OpenSans.ttf │ │ ├── OpenSansBold.ttf │ │ ├── OpenSansBoldItalic.ttf │ │ ├── OpenSansItalic.ttf │ │ ├── OpenSansLight.ttf │ │ ├── OpenSansLightItalic.ttf │ │ ├── Raleway.ttf │ │ ├── RalewayBold.ttf │ │ ├── Roboto.ttf │ │ ├── RobotoBold.ttf │ │ ├── RobotoLight.ttf │ │ ├── RobotoMedium.ttf │ │ ├── SourceSansPro.ttf │ │ ├── SourceSansProBold.ttf │ │ ├── SourceSansProItalic.ttf │ │ ├── SourceSansProLight.ttf │ │ └── Ubuntu.ttf │ ├── journal.min.css │ ├── lumen.min.css │ ├── paper.min.css │ ├── readable.min.css │ ├── sandstone.min.css │ ├── simplex.min.css │ ├── spacelab.min.css │ ├── united.min.css │ └── yeti.min.css ├── fonts │ ├── glyphicons-halflings-regular.eot │ ├── glyphicons-halflings-regular.svg │ ├── glyphicons-halflings-regular.ttf │ ├── glyphicons-halflings-regular.woff │ └── glyphicons-halflings-regular.woff2 └── shim │ ├── html5shiv.min.js │ └── respond.min.js ├── custom-css.css ├── highlightjs-9.12.0 ├── default.css ├── highlight.js └── textmate.css ├── navigation-1.1 ├── codefolding.js ├── sourceembed.js └── tabsets.js └── tocify-1.9.1 ├── jquery.tocify.css └── jquery.tocify.js /.github/workflows/jekyll-gh-pages.yml: -------------------------------------------------------------------------------- 1 | # Sample workflow for building and deploying a Jekyll site to GitHub Pages 2 | name: Deploy Jekyll with GitHub Pages dependencies preinstalled 3 | 4 | on: 5 | # Runs on pushes targeting the default branch 6 | push: 7 | branches: ["master"] 8 | 9 | # Allows you to run this workflow manually from the Actions tab 10 | workflow_dispatch: 11 | 12 | # Sets permissions of the GITHUB_TOKEN to allow deployment to GitHub Pages 13 | permissions: 14 | contents: read 15 | pages: write 16 | id-token: write 17 | 18 | # Allow only one concurrent deployment, skipping runs queued between the run in-progress and latest queued. 19 | # However, do NOT cancel in-progress runs as we want to allow these production deployments to complete. 20 | concurrency: 21 | group: "pages" 22 | cancel-in-progress: false 23 | 24 | jobs: 25 | # Build job 26 | build: 27 | runs-on: ubuntu-latest 28 | steps: 29 | - name: Checkout 30 | uses: actions/checkout@v4 31 | - name: Setup Pages 32 | uses: actions/configure-pages@v5 33 | - name: Build with Jekyll 34 | uses: actions/jekyll-build-pages@v1 35 | with: 36 | source: ./docs 37 | destination: ./_site 38 | - name: Upload artifact 39 | uses: actions/upload-pages-artifact@v3 40 | 41 | # Deployment job 42 | deploy: 43 | environment: 44 | name: github-pages 45 | url: ${{ steps.deployment.outputs.page_url }} 46 | runs-on: ubuntu-latest 47 | needs: build 48 | steps: 49 | - name: Deploy to GitHub Pages 50 | id: deployment 51 | uses: actions/deploy-pages@v4 52 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | 2 | Library/map-world.dbf 3 | Library/map-world.prj 4 | Library/map-world.shp 5 | Library/map-world.shx 6 | Library/results.xlsx 7 | Library/world_shape.dta 8 | Library/world_shape_coord.dta 9 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2020 World Bank Group 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /Library/Master.do: -------------------------------------------------------------------------------- 1 | /*============================================================================== 2 | 3 | * STATA VISUAL LIBRARY MASTER DO FILE 4 | 5 | ==============================================================================*/ 6 | 7 | /******************************************************************************* 8 | PART 1: Set folder paths 9 | *******************************************************************************/ 10 | 11 | if ("`c(username)'" == "ifyou") { 12 | global GH "D:/Documents/RA Jobs/DIME/analytics/stata-visual-library" 13 | } 14 | 15 | if ("`c(username)'" == "") { 16 | global GH 17 | } 18 | 19 | /******************************************************************************* 20 | PART 2: Create document 21 | *******************************************************************************/ 22 | 23 | // Set scheme color 24 | set scheme s2color 25 | 26 | * Copy the Stata style to the same folder as the markdown file to compile in PDF 27 | //copy https://www.stata-journal.com/production/sjlatex/stata.sty stata.sty 28 | 29 | global ScatterPlots `""binned-scatter","scatter-fl", "scatter-fl-ci", "scatter-poly-ci", "scatter-strata", "scatter-transparent", "dot-summary""' 30 | global BoxPlots `""boxplot-pctile""' 31 | global BarPlots `""bar-better", "bar-betterbar", "bar-better-ci", "bar-over", "bar-stack-by", "bar-stack-cat", "bar-two-axes", "confidence-intervals""' 32 | global LinePlots `""line-fit-text", "line-plottig", "line-uncluttered""' 33 | global DensityPlots `""density-av", "density-data", "density-shaded""' 34 | global RegressionCoef `""reg-models", "reg-chartable", "reg-het", "reg-predicted""' 35 | global Map `""map-world""' 36 | global EventStudy `""eventstudy-prepost""' 37 | 38 | foreach category in EventStudy ScatterPlots BoxPlots LinePlots DensityPlots RegressionCoef Map BarPlots { 39 | 40 | do "${GH}/Library/template-category-page.do" "`category'" 41 | tokenize `"${`category'}"' 42 | 43 | local n : word count "${`category'}" 44 | 45 | forvalues graph = 1(2)`n' { 46 | 47 | noi di "``graph''" 48 | 49 | mat drop _all 50 | gr drop _all 51 | 52 | set scheme s2color 53 | 54 | do "${GH}/Library/do/``graph''.do" 55 | gr export "${GH}/docs/figure/``graph''.png", height(600) replace 56 | copy "${GH}/Library/do/``graph''.do" "${GH}/Library/``graph''.html", replace 57 | do "${GH}/Library/template-plot-page.do" "``graph''" 58 | 59 | } 60 | } 61 | 62 | foreach file in "map-world.prj" "map-world.dbf" "map-world.shx" "map-world.shp" "world_shape.dta" "world_shape_coord.dta" { 63 | erase "${GH}/Library/`file'" 64 | } 65 | 66 | *============================== THE END =======================================* 67 | -------------------------------------------------------------------------------- /Library/ado/README.md: -------------------------------------------------------------------------------- 1 | this is a placeholder 2 | -------------------------------------------------------------------------------- /Library/ado/chartable.sthlp: -------------------------------------------------------------------------------- 1 | {smcl} 2 | {* Apr 1st 2015} 3 | {hline} 4 | Help for {hi:chartable} 5 | {hline} 6 | 7 | {title:Description} 8 | 9 | {p}{cmd:chartable} generates a chart of primary regression results for a variable list, combined with a table detailing those results. 10 | 11 | {title:Syntax} 12 | 13 | {p 2 4}{cmd:chartable} {it:depvars} [{help if}] [{help in}], {opt c:ommand(estimation_command)} {opt rhs(indepvar [controlvars])} 14 | {break} [{opt or}] [{opt p:stars}] [{opt globalif}] [{opt regopts(regression_options)}] [{it:tw_options}] 15 | 16 | {synoptset 16 tabbed}{...} 17 | {marker Options}{...} 18 | {synopthdr:Options} 19 | {synoptline} 20 | {p2coldent:* {opt c:ommand()}}Indicates the estimation command to be utilized.{p_end} 21 | {synopt:{opt rhs()}}Specify the right-hand-side variables, beginning with the input of interest and listing control variables if desired.{p_end} 22 | {synopt:{opt or()}}Specifies odds ratios, indicating a logistic regression is to be used. *Currently the only available option.*{p_end} 23 | {synopt:{opt p:stars()}}Adds stars indicating p-values to the estimates in the table.{p_end} 24 | {synopt:{opt globalif}}When applied, allows an if-condition to be set for each dependent variable separately. Before running the command with this option, create a global variable containing “7” followed by the logic expression needed for that variable. (Such as {it: global depvar & ifvar==1}).{p_end} 25 | {synopt:{opt regopts()}}Set any desired options for the regression command.{p_end} 26 | {synopt:{it:tw_options}}Specify any options needed for the graph.{p_end} 27 | {synoptline} 28 | {p 4 6 2}{it:(A * indicates required options.)}{p_end} 29 | 30 | {title:Author} 31 | 32 | Benjamin Daniels 33 | bbdaniels@gmail.com 34 | 35 | {p_end} -------------------------------------------------------------------------------- /Library/ado/custombar.sthlp: -------------------------------------------------------------------------------- 1 | {smcl} 2 | {* Apr 1th 2015} 3 | {hline} 4 | Help for {hi:custombar} 5 | {hline} 6 | 7 | {title:Description} 8 | 9 | {p}{cmd:custombar} produces bar graphs with grouping of variables, standard error bars, and cross-group comparisons. 10 | 11 | {title:Syntax} 12 | 13 | {p 2 4}{cmd:custombar} {help varlist} [{help if}] [{help in}] [{help using}], [{it:options}] [{help twoway_options}] 14 | 15 | {synoptset 16 tabbed}{...} 16 | {marker Options}{...} 17 | {synopthdr:Primary Options} 18 | {synoptline} 19 | {p2coldent:* {it:varlist}}The list of variables can be entered as usual or in parenthetical groups to produce ordering. {break}For example: {it:(animal_vars) (vegetable_vars) (mineral_vars)}.{p_end} 20 | {break} 21 | {synopt:{opt using}}Export the collapsed dataset to the specified spreadsheet.{p_end} 22 | {break} 23 | {synopt:{opth by(varlist)}}Produces top-level grouping of bars by specified variables.{p_end} 24 | {synopt:{opth o:ver(varlist)}}Produces bottom-level grouping of bars.{p_end} 25 | {break} 26 | {synopthdr:Graph Options} 27 | {synoptline} 28 | {synopt:{opt nobylabel}}Suppresses labelling from by-group.{p_end} 29 | {synopt:{opt nobycolor}}Suppresses coloring by by-group.{p_end} 30 | {synopt:{opt novarlab}}Suppresses labeling by variable.{p_end} 31 | {synopt:{opt nobarplot}}Suppresses bar chart.{p_end} 32 | {break} 33 | {synopt:{opt stat()}}Produces any {help collapse} statistic instead of means. Not recommended to combine with {opt se}.{p_end} 34 | {synopt:{opt v:ertical}}Produces vertical bars. The default is horizontal.{p_end} 35 | {synopt:{opt labsize()}}Specify label size for variable axis.{p_end} 36 | {synopt:{opt barlook()}}Specify bar styling options, up to one for each lowest-level category, as: {bf:barlook(}1 {help barlook_options} 2 {help barlook_options} ...{bf:)}.{p_end} 37 | {break} 38 | {synopthdr:Added Statistics} 39 | {synoptline} 40 | {synopt:{opt addplot()}}Specify a list of twoway plots to add to the chart. The categorical axis is variable {it:x}, ranging from 0 to 1, and the numerical axis is variable {it:mean}. Over-groups and by-groups are named and numbered as in the original data with the original variable names. Variables can be specified as "if varname == {it:varname}".{p_end} 41 | {break} 42 | {synopt:{opth stats(varlist)}}Displays the sample size and the means of the specified variables. Adjustments can be made by specifying {bf:caption()} in {help twoway_options}.{p_end} 43 | {synopt:{opt n}}Adds group sizes to legend.{p_end} 44 | {break} 45 | {synopt:{opt se}}Includes standard error bars around the calculated statistics adjusted to the 95% confidence interval, calculated as 1.96*SE(mean).{p_end} 46 | {synopt:{opt bin:omial}}Uses binomial distribution standard errors. The default is normal.{p_end} 47 | {break} 48 | {synopt:{opt bar:lab()}}Labels the bars with the mean values. Specify {it:upper, lower, mean, or zero} to control the placement of the label - at the upper or lower bound of the confidence interval, at the mean (the end of the bar) or at the zero point.{p_end} 49 | {break} 50 | {synopthdr:Sorting} 51 | {synoptline} 52 | {synopt:{opt d:escending()}}Sorts bars with the highest value first. {p_end} 53 | {synopt:{opt a:scending()}}Sorts bars with the lowest value first.{p_end} 54 | {synopt:}Inside the parentheses should be a logic expression indicating the group to sort by. For example: {opt descending(treament==1 & male==1)}. If no {opt over}- or {opt by}-groups are specified, use {opt descending(1)}.{p_end} 55 | 56 | {synoptline} 57 | {p 4 6 2}{p_end} 58 | 59 | {title:Author} 60 | 61 | Benjamin Daniels 62 | bbdaniels@gmail.com 63 | 64 | {p_end} 65 | -------------------------------------------------------------------------------- /Library/ado/freeshape.ado: -------------------------------------------------------------------------------- 1 | ** Reshapes to long for with non-stub names 2 | 3 | cap prog drop freeshape 4 | prog def freeshape 5 | 6 | syntax varlist , i(string asis) j(string asis) 7 | 8 | qui { // To long form 9 | 10 | * Rename variables for reshape, recording name and label 11 | 12 | local x = 0 // Variable index 13 | 14 | foreach var of varlist `varlist' { 15 | local ++x 16 | rename `var' `j'`x' 17 | local `j'`x'_name "`var'" 18 | local `j'`x'_label : var label `j'`x' 19 | } 20 | 21 | * Reshape 22 | 23 | reshape long `j' , i(`i') j(`j'_index) 24 | 25 | * Names and labels 26 | 27 | label var `j'_index "Index #" 28 | rename `j' `j'_value 29 | label var `j'_value "Value" 30 | gen `j'_name = "" 31 | label var `j'_name "Name" 32 | gen `j'_label = "" 33 | label var `j'_label "Label" 34 | forvalues varindex = 1/`x' { 35 | replace `j'_name = "``j'`varindex'_name'" if `j'_index == `varindex' 36 | replace `j'_label = "``j'`varindex'_label'" if `j'_index == `varindex' 37 | } 38 | 39 | * Variable order 40 | 41 | order `i' `j'_index `j'_name `j'_label `j'_value, first 42 | 43 | } 44 | 45 | end 46 | -------------------------------------------------------------------------------- /Library/ado/freeshape.sthlp: -------------------------------------------------------------------------------- 1 | {smcl} 2 | {* March 13th 2014} 3 | {hline} 4 | Help for {hi:freeshape} 5 | {hline} 6 | 7 | {title:Description} 8 | 9 | {p}{cmd:freeshape} reshapes any variable list to long-format. Unlike reshape, it does not require that the variables be named with numbered stubs. It generates a sequenced ID from the {opt j()} option, and creates variables recording the original variable names, labels, and values, named {it:j_index, j_name, j_label,} and {it:j_value}, respectively. 10 | 11 | {title:Syntax} 12 | 13 | {p}{cmd:freeshape} {it:varlist}, {opt i(id_varlist)} {opt j(newvar_stub)} 14 | 15 | {title:Author} 16 | 17 | Benjamin Daniels 18 | bbdaniels@gmail.com 19 | 20 | {p_end} -------------------------------------------------------------------------------- /Library/ado/labelcollapse.ado: -------------------------------------------------------------------------------- 1 | * Collapses while preserving labels 2 | 3 | cap prog drop labelcollapse 4 | prog def labelcollapse 5 | 6 | syntax anything [if] [in] [fweight aweight pweight iweight], [vallab(varlist)] [n] [*] 7 | 8 | if "`n'" == "n" { 9 | tempname n 10 | gen `n' = 1 11 | local ncollapse (sum) `n' 12 | label var `n' "N" 13 | } 14 | 15 | if "`weight'" != "" { 16 | local theWeight [`weight' `exp'] 17 | } 18 | 19 | foreach item in `anything' { 20 | if strpos("`item'",")") == 0 { 21 | local theVarlist `theVarlist' `item' 22 | } 23 | } 24 | 25 | if "`vallab'" != "" { 26 | foreach var of varlist `vallab' { 27 | qui levelsof `var', local(levels) 28 | 29 | local theLabelList "" 30 | foreach level in `levels' { 31 | local theValLab : label (`var') `level' 32 | local theLabelList `" `theLabelList' `level' "`theValLab'" "' 33 | } 34 | cap label drop `var'_l 35 | label def `var'_l `theLabelList' 36 | } 37 | } 38 | 39 | foreach var of varlist `theVarlist' { 40 | local `var'L : var label `var' 41 | } 42 | 43 | collapse `anything' `ncollapse' `if' `in' `theWeight', `options' 44 | 45 | foreach var of varlist `theVarlist' { 46 | label var `var' "``var'L'" 47 | cap label val `var' `var'_l 48 | } 49 | 50 | end 51 | -------------------------------------------------------------------------------- /Library/ado/labelcollapse.sthlp: -------------------------------------------------------------------------------- 1 | {smcl} 2 | {* Jun 4th 2014} 3 | {hline} 4 | Help for {hi:labelcollapse} 5 | {hline} 6 | 7 | {title:Description} 8 | 9 | {p}{cmd:labelcollapse} preserves variable labeling while performing {help collapse}. 10 | 11 | {title:Syntax} 12 | 13 | {p}{cmd:labelcollapse} {it:clist} [{help if}] [{help in}] [{help weight}] , [{opth vallab(varlist)}] [{it:collapse_options}] 14 | 15 | {title:Instructions} 16 | 17 | {p}Instead of running {help collapse}, use {cmd:labelcollapse} to preserve variable labels. Specify {opt vallab()} to preserve value labels for the specified {help varlist}. The rest of the syntax is identical. 18 | 19 | {title:Author} 20 | 21 | Benjamin Daniels 22 | bbdaniels@gmail.com 23 | 24 | {p_end} -------------------------------------------------------------------------------- /Library/ado/reftab.sthlp: -------------------------------------------------------------------------------- 1 | {smcl} 2 | {* December 24th 2014} 3 | {hline} 4 | Help for {hi:reftab} 5 | {hline} 6 | 7 | {title:Description} 8 | 9 | {p}{cmd:reftab} displays and can also write a matrix of summary statistics and regression results using {help xml_tab}, containing the means of the requested variable(s) and estimated marginal effects of membership in various categories of a by-variable. 10 | 11 | {title:Syntax} 12 | 13 | {p 2 4}{cmd:reftab} {help varlist} [{help using}] [{help if}] [{help in}], {opth by:var(varname)} {opt ref:cat(base_value)} [{opth iv(varname)}] 14 | {break} [{opth controls(varlist)}] [{opt logit}] [{opt cl:uster(clustvar)}] [{opt dec:imals()}] [{opt n}] [{opt se:m}] [{it:xml_tab_options}] 15 | 16 | {title:Instructions} 17 | 18 | {p}The first panel of the table will contain means of the specified variables by categories of {opt by:var()}, with standard errors if {opt se:m} is specified. Each successive panel will report the regression coefficients for each category of {bf:byvar} from a regression on the full set of group membership indicators with the {opt ref:cat()} value excluded. If {opt controls()} are specified, each panel will also contain the estimates from the fixed-effects regression controlled for the specified variables. 19 | 20 | {p}If {bf:logit} is specified, the differences will be calculated as odds ratios. If {bf:iv} is specified, the final panel will contain the second-stage estimate of the effect of the variable specified, instrumented on the full set of category indicators. It will include an adjusted estimate as well if {opt controls()} are specified. 21 | 22 | {p}In {opt dec:imals}, specify the number of decimal places to be reported for each variable, for example, {bf:decimals(}2 0 1 2{bf:)} if there are four variables and 2, 0, 1, and 2 places are desired. This also affects the standard error formatting. This only applies if an output file for {help xml_tab} is specified in {help using}, and supersedes the {bf:format()} option from {help xml_tab}. Specifying {bf:n} adds sample sizes to the means panel (which may differ from the sample sizes used in regression if control variables are missing). 23 | 24 | {title:Author} 25 | 26 | Benjamin Daniels 27 | bbdaniels@gmail.com 28 | 29 | {p_end} -------------------------------------------------------------------------------- /Library/ado/tabgen.ado: -------------------------------------------------------------------------------- 1 | ** Tab-gen with proper labelling 2 | 3 | cap prog drop tabgen 4 | prog def tabgen 5 | 6 | syntax varlist 7 | 8 | cap label def yesnobin 0 "No" 1 "Yes" 9 | 10 | foreach var of varlist `varlist' { 11 | 12 | qui levelsof `var' , local(levels) 13 | 14 | foreach level in `levels' { 15 | gen `var'_`level' = (`var' == `level') 16 | local theLabel : label (`var') `level' 17 | 18 | label var `var'_`level' "`theLabel'" 19 | 20 | label val `var'_`level' yesnobin 21 | 22 | local theList = "`theList' `var'_`level'" 23 | } 24 | 25 | } 26 | 27 | codebook `theList' , compact 28 | 29 | end 30 | -------------------------------------------------------------------------------- /Library/ado/tabgen.sthlp: -------------------------------------------------------------------------------- 1 | {smcl} 2 | {* May 14th 2014} 3 | {hline} 4 | Help for {hi:tabgen} 5 | {hline} 6 | 7 | {title:Description} 8 | 9 | {p}{cmd:tabgen} splits categorical variables into binaries and correctly labels each category. 10 | 11 | {title:Syntax} 12 | 13 | {p}{cmd:tabgen} {it:varlist} 14 | 15 | {title:Author} 16 | 17 | Benjamin Daniels 18 | bbdaniels@gmail.com 19 | 20 | {p_end} -------------------------------------------------------------------------------- /Library/ado/tabstatout.sthlp: -------------------------------------------------------------------------------- 1 | {smcl} 2 | {* Jun 4th 2014} 3 | {hline} 4 | Help for {hi:tabstatout} 5 | {hline} 6 | 7 | {title:Description} 8 | 9 | {p}{cmd:tabstatout} produces a table of summary statistics and can also export to a spreadsheet if {help xml_tab} is installed. 10 | 11 | {title:Syntax} 12 | 13 | {p 2 4}{cmd:tabstatout} {it:statlist} [{help using}] [{help if}] [{help in}] [{help weight}] , {opth by(varname)} 14 | {break} [{opt n}] [{opt sd}] [{opt t:otal}] [{opt trans:pose}] [{opt dec:imals()}] [{it:xml_tab_options}] 15 | 16 | {title:Instructions} 17 | 18 | {p}In {it:statlist}, specify the statistics you would like to calculate, using the syntax from {help collapse}. Specify {bf:n} to attach a count row to the end of the table. Specify {opt t:otal} to attach a summary column to the end of the table. Specify {opt trans:pose} to transpose the table. Specify {bf:sd} to add standard deviations (of the means) under every statistic. 19 | 20 | {p}In {opt dec:imals}, specify the number of decimal places for each statistic, for example, {bf:decimals(}2 2 2 2 2 0 1 2{bf:)} Add x to a number, for example, {bf:decimals(}2x 2 2 2 2 0 1x 2{bf:)} to suppress standard errors. This only applies if an output file for {help xml_tab} is specified in {help using}, and supersedes the {bf:format()} option from {help xml_tab}. 21 | 22 | {title:Author} 23 | 24 | Benjamin Daniels 25 | bbdaniels@gmail.com 26 | 27 | {p_end} -------------------------------------------------------------------------------- /Library/ado/weightab.sthlp: -------------------------------------------------------------------------------- 1 | {smcl} 2 | {* Sep 8th 2015} 3 | {hline} 4 | Help for {hi:weightab} 5 | {hline} 6 | 7 | {title:Description} 8 | 9 | {p}{cmd:weightab} produces xlsx sheets and/or bar graphs with weighted cross-group comparisons. 10 | 11 | {title:Syntax} 12 | 13 | {p 2 4}{cmd:weightab} {help varlist} [{help if}] [{help in}] [{help using}] [{help weight}], {opth over(varlist)} [{it:options}] 14 | 15 | {synoptset 16 tabbed}{...} 16 | {marker Options}{...} 17 | {synopthdr:Primary Options} 18 | {synoptline} 19 | {p2coldent:* {it:varlist}}The list of variables to produce summary statistics for. Calculations are based on {help svy}: {help mean} using supplied weights.{p_end} 20 | {p2coldent:* {opt weight}}Specify weight variable. Only pweights are currently supported.{p_end} 21 | {p2coldent:* {opth o:ver(varlist)}}Produces grouping of observations. Values should be labeled.{p_end} 22 | {break} 23 | {synopthdr:XLSX Options} 24 | {synoptline} 25 | {p2coldent:+ {opt using}}Export the final statistics to the specified spreadsheet.{p_end} 26 | {synopt:{opt stats()}}Choose from {help mean}'s [{it:b se t pvalue ll ul df crit}] statistics for reporting. The default is stats(b se).{p_end} 27 | {break} 28 | {synopthdr:Graph Options} 29 | {synoptline} 30 | {p2coldent:+ {opt graph}}Requests bar graph of results.{p_end} 31 | {synopt:{opt se}}Requests 95% CIs around point estimates.{p_end} 32 | {synopt:{opt dropzero}}Excludes bars with b=0.{p_end} 33 | {synopt:{opt barlook()}}Specify bar styling options, up to one for each lowest-level category, as: {bf:barlook(}1 {help barlook_options} 2 {help barlook_options} ...{bf:)}.{p_end} 34 | {synopt:{help twoway_options}}Specify as usual.{p_end} 35 | 36 | {synoptline} 37 | {p 4 6 2}{p_end} 38 | 39 | {title:Author} 40 | 41 | Benjamin Daniels 42 | bbdaniels@gmail.com 43 | 44 | 45 | -------------------------------------------------------------------------------- /Library/bar-better-ci.html: -------------------------------------------------------------------------------- 1 | /* 2 | Figure: Horizontal bar plot with grouping of variables, standard error bars, and cross-group comparisons 3 | 4 | Data Source: 5 | --------------------- 6 | 7 | Satyanarayana S, Kwan A, Daniels B, Subbaraman R, McDowell A, Bergkvist S, Das RK, Das V, Das J, Pai M. 8 | Use of standardised patients to assess antibiotic dispensing for tuberculosis by pharmacies in urban India: A cross-sectional study. 9 | The Lancet Infectious Diseases. 2016 Nov 30;16(11):1261-8. 10 | */ 11 | 12 | global pct `" 0 "0%" .25 "25%" .5 "50%" .75 "75%" 1 "100%" "' 13 | 14 | qui do "https://github.com/worldbank/stata-visual-library/raw/master/Library/ado/betterbar.ado" 15 | 16 | use "https://github.com/worldbank/stata-visual-library/raw/master/Library/data/bar-better-ci.dta", clear 17 | 18 | betterbar /// 19 | (dr_3 correct_treatment) /// 20 | (med_b2_any_antibiotic med_b2_any_steroid med_b2_any_antister med_l_any_2 /// 21 | med_b2_any_schedule_h med_b2_any_schedule_h1 med_b2_any_schedule_x med_l_any_1), /// 22 | over(city) xlab($pct) se bin /// 23 | legend(pos(5) ring(0) c(1) symxsize(small) symysize(small)) /// 24 | ysize(7) n barlab(upper) /// 25 | title ("Horizontal Cluster Bar Plot" , justification(left) color(black) span pos(17)) 26 | 27 | * Have a lovely day! 28 | -------------------------------------------------------------------------------- /Library/bar-better.html: -------------------------------------------------------------------------------- 1 | /* 2 | Figure: Horizontal bar with multiple variables 3 | 4 | Data Source: 5 | --------------------- 6 | Daniels, Benjamin, Amy Dolinger, Guadalupe Bedoya, Khama Rogo, Ana Goicoechea, Jorge Coarasa, Francis Wafula, 7 | Njeri Mwaura, Redemptar Kimeu, and Jishnu Das. “Use of standardised patients to assess quality of healthcare in Nairobi, 8 | Kenya: a pilot, cross-sectional study with international comparisons.” BMJ global health 2, no. 2 (2017): e000333. 9 | */ 10 | global graph_opts /// 11 | title(, justification(left) color(black) span pos(11)) /// 12 | graphregion(color(white)) /// 13 | ylab(,angle(0) nogrid) /// 14 | xtit(,placement(left) justification(left)) /// 15 | yscale(noline) xscale(noline) /// 16 | legend(region(lc(none) fc(none))) 17 | 18 | global pct `" 0 "0%" .25 "25%" .5 "50%" .75 "75%" 1 "100%" "' 19 | 20 | qui do "https://github.com/worldbank/stata-visual-library/raw/master/Library/ado/betterbar.ado" 21 | 22 | use "https://github.com/worldbank/stata-visual-library/raw/master/Library/data/bar-better.dta" , clear 23 | 24 | betterbar /// 25 | ??_correct checklist refer med_any med_class_any_6 med_class_any_16 /// 26 | , /// 27 | ${graph_opts} /// 28 | over(facility_type) /// 29 | xlab(${pct}) /// 30 | barlab(mean) /// 31 | legend(r(1) symxsize(small) symysize(small)) /// 32 | title("Horizontal Cluster Bar Plot") 33 | 34 | 35 | * Have a lovely day! 36 | -------------------------------------------------------------------------------- /Library/bar-over.html: -------------------------------------------------------------------------------- 1 | /* 2 | Figures: bar plot of two variables 3 | 4 | Data Source: 5 | --------------------- 6 | Das, Jishnu, Liana Woskie, Ruma Rajbhandari, Kamran Abbasi, and Ashish Jha. 7 | “Rethinking assumptions about delivery of healthcare: implications for universal health coverage.” Bmj 361 (2018). 8 | */ 9 | 10 | global graph_opts1 /// 11 | bgcolor(white) /// 12 | graphregion(color(white)) /// 13 | legend(region(lc(none) fc(none))) /// 14 | ylab(,angle(0) nogrid) /// 15 | title(, justification(center) color(black) span pos(17)) /// 16 | subtitle(, justification(left) color(black)) 17 | 18 | use "https://github.com/worldbank/stata-visual-library/raw/master/Library/data/bar-over.dta" , clear 19 | 20 | graph bar treat_correct /// 21 | , /// 22 | over(type) /// 23 | asy /// 24 | bargap(20) /// 25 | over(study) /// 26 | over(case) /// 27 | nofill /// 28 | blabel(bar, format(%9.2f)) /// 29 | ${graph_opts1} /// 30 | bar(1 , lc(black) lw(thin) fi(100)) /// 31 | bar(2 , lc(black) lw(thin) fi(100)) /// 32 | legend(r(1) /// 33 | order(0 "Measurement:" 1 "Standardized Patient" 2 "Clinical Vignette")) /// 34 | ytit("Providers ordering correct treatment {&rarr}", /// 35 | placement(bottom) /// 36 | justification(left)) /// 37 | ylab(${pct}) /// 38 | title("Bar Plot of Two Variables") 39 | 40 | * Have a lovely day! 41 | -------------------------------------------------------------------------------- /Library/bar-stack-by.html: -------------------------------------------------------------------------------- 1 | /* 2 | Figure: Stack bar graph by two variables (Drug use by referral decisions for two standardised patient cases) 3 | 4 | Data Source: 5 | --------------------- 6 | 7 | Satyanarayana S, Kwan A, Daniels B, Subbaraman R, McDowell A, Bergkvist S, Das RK, Das V, Das J, Pai M. 8 | Use of standardised patients to assess antibiotic dispensing for tuberculosis by pharmacies in urban India: 9 | A cross-sectional study. The Lancet Infectious Diseases. 2016 Nov 30;16(11):1261-8. 10 | 11 | 12 | Install Packages (if needed) 13 | ----------------------------- 14 | We need one packages to run this file: grc1leg 15 | Please remove "*" from below lines if you have not installed it and would like to install. 16 | */ 17 | 18 | * net install grc1leg, from(http://www.stata.com/users/vwiggins) 19 | 20 | global graph_opts1 bgcolor(white) graphregion(color(white)) legend(region(lc(none) fc(none))) ylab(,angle(0) nogrid) subtitle(, justification(left) color(black) span pos(11)) title(, justification(center) color(black) span pos(17)) 21 | global pct `" 0 "0%" .25 "25%" .5 "50%" .75 "75%" 1 "100%" "' 22 | 23 | use "https://github.com/worldbank/stata-visual-library/raw/master/Library/data/bar-stack-by.dta", clear 24 | 25 | graph bar med_b2_antister_cat?? /// 26 | if dr_3 == 1 /// 27 | , /// 28 | stack over(checkgroup) nofill /// 29 | ylab(${pct}) /// 30 | legend(order(5 "No Medication" /// 31 | 4 "Antibiotic and Steroid" /// 32 | 3 "Antibiotic" /// 33 | 2 "Steroid" /// 34 | 1 "No Antibiotic or Steroid") /// 35 | c(1) pos(3) /// 36 | symxsize(small) symysize(small) size(small)) /// 37 | ${graph_opts1} /// 38 | bar(5, color(white) lc(black) lp(solid) lw(thin)) /// 39 | bar(1,lw(thin) lc(black)) bar(2,lw(thin) lc(black)) /// 40 | bar(3,lw(thin) lc(black)) bar(4,lw(thin) lc(black)) /// 41 | subtitle("Referral", color(black) justification(center) pos(12)) /// 42 | name(figure_1) 43 | 44 | graph bar med_b2_antister_cat?? /// 45 | if dr_3 == 0 /// 46 | , /// 47 | stack over(checkgroup) nofill /// 48 | ylab(${pct}) /// 49 | legend(order(5 "No Medication" /// 50 | 4 "Antibiotic and Steroid" /// 51 | 3 "Antibiotic" /// 52 | 2 "Steroid" /// 53 | 1 "No Antibiotic or Steroid") /// 54 | c(1) pos(3) /// 55 | symxsize(small) symysize(small) size(small)) /// 56 | ${graph_opts1} /// 57 | bar(5, color(white) lc(black) lp(solid) lw(thin)) /// 58 | bar(1,lw(thin) lc(black)) /// 59 | bar(2,lw(thin) lc(black)) /// 60 | bar(3,lw(thin) lc(black)) /// 61 | bar(4,lw(thin) lc(black)) /// 62 | subtitle("No Referral", color(black) justification(center) pos(12)) /// 63 | name(figure_2) 64 | 65 | grc1leg figure_2 figure_1 /// 66 | , /// 67 | title ("Stack Bar Chart") /// 68 | pos(3) /// 69 | graphregion(color(white)) /// 70 | xsize(7) /// 71 | rows(1) /// 72 | leg(figure_2) 73 | 74 | * Have a lovely day! 75 | -------------------------------------------------------------------------------- /Library/bar-stack-cat.html: -------------------------------------------------------------------------------- 1 | /* 2 | Figure: horizontal stack bar plot 3 | 4 | Data Source: 5 | --------------------- 6 | Kwan, Ada, Benjamin Daniels, Vaibhav Saria, Srinath Satyanarayana, Ramnath Subbaraman, Andrew McDowell, 7 | Sofi Bergkvist et al. “Variations in the quality of tuberculosis care in urban India: a cross-sectional, 8 | standardized patient study in two cities.” PLoS medicine 15, no. 9 (2018): e1002653. 9 | 10 | */ 11 | global graph_opts1 /// 12 | graphregion(color(white) lc(white) la(center)) /// <- remove la(center) for Stata < 15 13 | ylab(,angle(0) nogrid) /// 14 | yscale(noline) legend(region(lc(none) fc(none))) 15 | 16 | global pct `" 0 "0%" .25 "25%" .5 "50%" .75 "75%" 1 "100%" "' 17 | 18 | use "https://github.com/worldbank/stata-visual-library/raw/master/Library/data/bar-stack-cat.dta" , clear 19 | 20 | local x = 0 21 | qui foreach var of varlist /// 22 | correct treat_cxr re_3 re_4 treat_refer /// 23 | med_any med_l_any_1 med_l_any_2 med_l_any_3 med_k_any_9 { 24 | 25 | mean `var' [pweight = weight_city] 26 | mat a = e(b) 27 | local mean = a[1,1] 28 | local mean = string(round(100*`mean',0)) 29 | local mean = substr("`mean'",1,strpos("`mean'",".")+1) 30 | 31 | local ++x 32 | local theLabel : var label `var' 33 | local theLabels `" `theLabels' `x' "`theLabel'" "' // [`mean'%] 34 | 35 | cap mat drop theResult 36 | reg `var' i.city [pweight = weight_city] 37 | local theR21 = `e(r2)' 38 | mat theResult = nullmat(theResult) , [`theR21'] 39 | 40 | reg `var' i.city i.case [pweight = weight_city] 41 | local theR22 = `e(r2)' - `theR21' 42 | mat theResult = nullmat(theResult) , [`theR22'] 43 | 44 | reg `var' i.city i.case i.type_formal [pweight = weight_city] 45 | local theR23 = `e(r2)' - `theR21' - `theR22' 46 | mat theResult = nullmat(theResult) , [`theR23'] 47 | 48 | reg `var' i.city i.case i.type_formal i.sp_city_id [pweight = weight_city] 49 | local theR24 = `e(r2)' - `theR21' - `theR22' - `theR23' 50 | mat theResult = nullmat(theResult) , [`theR24'] 51 | 52 | reg `var' i.city i.case i.type_formal i.sp_city_id i.sp_city_mbbs [pweight = weight_city] 53 | local theR25 = `e(r2)' - `theR21' - `theR22' - `theR23' - `theR24' 54 | mat theResult = nullmat(theResult) , [`theR25'] 55 | 56 | mean `var' [pweight = weight_city] 57 | mat a = e(b) 58 | local mean = a[1,1] 59 | mat theResult = nullmat(theResult) , [`mean'] 60 | 61 | mat theResults = nullmat(theResults) \ theResult 62 | matlist theResults 63 | 64 | } 65 | 66 | clear 67 | svmat theResults 68 | gen n = _n 69 | label def n `theLabels' 70 | label val n n 71 | 72 | graph bar (sum) theResults1 theResults2 theResults3 theResults4 theResults5 /// 73 | , /// 74 | ylab($pct) /// 75 | ${graph_opts1} /// 76 | title("Horizontal Stack Bar Chart", justification(left) color(black) span pos(17)) /// 77 | hor stack over(n) xsize(6) /// 78 | bar(1, lc(black) lw(thin)) /// 79 | bar(2, lc(black) lw(thin)) /// 80 | bar(3, lc(black) lw(thin)) /// 81 | bar(4, fc(black) lc(black) lw(thin)) /// 82 | bar(5, fc(gs12) lc(black) lw(thin)) /// 83 | legend(pos(5) ring(0) c(1) symxsize(small) symysize(small) /// 84 | order(6 "Variance Explained By:" /// 85 | 1 "City Setting" /// 86 | 2 "Case Scenario" /// 87 | 3 "MBBS Degree" /// 88 | 4 "All SP Characteristics" /// 89 | 5 "Full Interaction Model")) 90 | 91 | * Have a lovely day! 92 | -------------------------------------------------------------------------------- /Library/bar-two-axes.html: -------------------------------------------------------------------------------- 1 | /* 2 | Figure: combined bar plots with two axex 3 | 4 | Data Source: 5 | --------------------- 6 | Mock data and code were based in 7 | Christian, Paul, and Brian Dillon. 2018. “Growing and Learning When Consumption Is Seasonal: 8 | Long-Term Evidence From Tanzania.” Demography 55 (3): 1091–1118. doi:10.1007/s13524-018-0669-4. 9 | */ 10 | 11 | use "https://github.com/worldbank/stata-visual-library/raw/master/Library/data/bar-two-axes.dta", clear 12 | 13 | gen x = int1mo+.5 /// Adjust variable for bar position 14 | 15 | foreach foodGroup in animal fruit grain veg starch processed_sugar { 16 | /// Create individual graphs using a loop 17 | if "`foodGroup'" == "animal" local graphTitle Animal Sourced 18 | if "`foodGroup'" == "fruit" local graphTitle Fruit 19 | if "`foodGroup'" == "grain" local graphTitle Grain 20 | if "`foodGroup'" == "veg" local graphTitle Vegetables 21 | if "`foodGroup'" == "starch" local graphTitle Starchy Foods 22 | if "`foodGroup'" == "processed_sugar" local graphTitle Processed/Sugar 23 | 24 | twoway bar number_group x if food_group=="`foodGroup'", /// 25 | yaxis(1) ytitle("Avg. Number of Foods from" "Group Consumed Last Month", axis(1)) /// 26 | barwidth(.9) fintensity(inten0) lcolor(black) /// 27 | xlabel(0 "0" 3 "3" 6 "6" 9 "9" 12 "12") /// 28 | ylabel(0 "0" 1 "1" 2 "2" 3 "3", axis(1)) || /// 29 | line total_exp int1mo if food_group=="`foodGroup'", /// 30 | yaxis(2) ytitle("Total Value of Exp." "1000 Real Tz Sh.", axis(2)) /// 31 | ylabel(0 "0" 500 "500" 1000 "1000" 1500 "1500" 2000 "2000" 2500 "2500", axis(2)) /// 32 | xlabel(3 "3" 6 "6" 9 "9" 12 "12") lwidth(1.2) /// 33 | title("`graphTitle'") xtitle("Month of Interview") /// 34 | graphregion(color(white)) bgcolor(white) /// 35 | legend(off) /// 36 | name("`foodGroup'") 37 | 38 | } 39 | 40 | graph combine starch animal fruit grain processed_sugar veg, /// 41 | title("Combined Bar Plot with Dual Axes", justification(center) color(black) span pos(17)) /// 42 | graphregion( color(white)) plotregion(color(white)) 43 | 44 | 45 | * Have a lovely day! 46 | -------------------------------------------------------------------------------- /Library/bar-weightab.html: -------------------------------------------------------------------------------- 1 | * Figure:Side by side horizontal bar plot (Outcomes by City & Case) using weightab 2 | 3 | global graph_opts /// 4 | title(, justification(left) color(black) span pos(11)) /// 5 | graphregion(color(white) lc(white) lw(med) la(center)) /// <- remove la(center) for Stata < 15 6 | ylab(,angle(0) nogrid) xtit(,placement(left) justification(left)) /// 7 | yscale(noline) xscale(noline) legend(region(lc(none) fc(none))) 8 | 9 | local opts lw(thin) lc(white) la(center) 10 | 11 | label def case 1 "Case 1" 2 "Case 2" 3 "Case 3" 4 "Case 4" , modify 12 | 13 | qui do "https://github.com/worldbank/stata-visual-library/raw/master/Library/ado/weightab.ado" 14 | 15 | use "https://github.com/worldbank/stata-visual-library/raw/master/Library/data/bar-weightab.dta" , clear 16 | 17 | weightab /// 18 | correct treat_cxr re_3 re_4 treat_refer t_12 /// 19 | med_any med_l_any_1 med_l_any_2 med_l_any_3 med_k_any_9 /// 20 | if city == 2 /// 21 | [pweight = weight_city] /// 22 | , /// 23 | ${graph_opts} /// 24 | barlab /// 25 | barlook(1 `opts' fi(100)) /// 26 | title("Patna") /// 27 | over(case) /// 28 | graph /// 29 | legend(off) /// 30 | xlab(${pct}) /// 31 | name(Fig_1_1) 32 | 33 | weightab /// 34 | correct treat_cxr re_3 re_4 treat_refer t_12 /// 35 | med_any med_l_any_1 med_l_any_2 med_l_any_3 med_k_any_9 /// 36 | if city == 3 /// 37 | [pweight = weight_city] /// 38 | , /// 39 | ${graph_opts} /// 40 | barlab /// 41 | barlook(1 `opts' fi(100)) /// 42 | title("Mumbai") /// 43 | over(case) /// 44 | graph /// 45 | legend(pos(5) ring(0) c(1) symxsize(small) symysize(small)) /// 46 | xlab(${pct}) /// 47 | name(Fig_1_2) 48 | 49 | graph combine Fig_1_1 Fig_1_2 /// 50 | , /// 51 | ${comb_opts} /// 52 | xsize(7) r(1) 53 | 54 | * Have a lovely day! 55 | -------------------------------------------------------------------------------- /Library/binned-scatter.html: -------------------------------------------------------------------------------- 1 | /* 2 | Figure: Binned scatter plot 3 | 4 | Data Source: 5 | --------------------- 6 | Jishnu Das, Benjamin Daniels, Monisha Ashok, Eun-Young Shim, and Karthik Muralidharan 7 | Two Indias: The structure of primary health care markets in rural Indian villages with implications for policy. 8 | doi: https://doi.org/10.1016/j.socscimed.2020.112799 9 | repo: https://github.com/bbdaniels/ssm-rhcp-2020 10 | */ 11 | 12 | use "https://github.com/worldbank/stata-visual-library/blob/bbd-graphs/Library/data/binned-scatter.dta?raw=true" , clear 13 | 14 | count 15 | recode s1q15 (-99 = .) 16 | count if s2q15 != . & s2q16 != . 17 | 18 | // Adjust number of patients for public clinics 19 | egen group = group(private mbbs) , label 20 | replace group = 2 if group == . 21 | bys finclinid: gen n = _N 22 | bys stateid finclinid_new: gen ndocs = _N 23 | replace patients = patients/ndocs if public == 1 24 | gen check = patients 25 | drop if (check > 120 | s2q16 == 0) 26 | 27 | // bin minutes per patient and calculate hours per day 28 | recode s2q16 (1/5 = 5)(6/10 = 10)(11/15 = 15)(16/20 = 20)(26/max=30) , gen(minpp) 29 | gen hours = check*s2q16/60 30 | gen pct = hours / 6 31 | mean hours pct patients s2q16 [pweight = weight_psu] , over(group) // average utilization 32 | 33 | // Graph 34 | replace minpp = minpp+1 if group == 1 // Public MBBS 35 | replace minpp = minpp-1 if group == 2 // Private non-MBBS 36 | 37 | local opts lc(gray) lw(thin) 38 | 39 | isid uid , sort 40 | version 13 41 | 42 | gen blank = . 43 | 44 | tw /// 45 | /// Invisible cheaters for legend 46 | (scatter blank blank in 1 , m(.) mc(black) msize(*2)) /// 47 | (scatter blank blank in 1 , m(T) mc("0 109 219") msize(*4)) /// 48 | (scatter blank blank in 1 , m(S) mc("146 0 0") msize(*4)) /// 49 | /// Actual graph points 50 | (scatter check minpp if private == 1 & mbbs == 0, /// 51 | jitter(2) jitterseed(382375) m(.) mc("0 0 0") msize(*.1)) /// 52 | (scatter check minpp if private == 1 & mbbs == 1, /// 53 | jitter(2) jitterseed(382375) m(T) mc("0 109 219") msize(*.4)) /// 54 | (scatter check minpp if private == 0 & mbbs == 1, /// 55 | jitter(2) jitterseed(382375) m(S) mc("146 0 0") msize(*.4)) /// 56 | /// Reference line 57 | (function 72, range(3 7.5) `opts') /// 58 | (pci 36 7.5 72 7.5 , `opts') /// 59 | (function 36, range(7.5 12.5) `opts') /// 60 | (pci 36 12.5 24 12.5 , `opts') /// 61 | (function 24, range(12.5 17.5) `opts') /// 62 | (pci 24 17.5 18 17.5 , `opts') /// 63 | (function 18, range(17.5 22.5) `opts') /// 64 | (pci 18 22.5 14.4 22.5 , `opts') /// 65 | (function 14.4, range(22.5 27.5) `opts') /// 66 | (pci 14.4 27.5 12 27.5 , `opts') /// 67 | (function 12, range(27.5 32) `opts') /// 68 | (scatteri 12 32 "6 Hour Workday" , m(none) mlabc(gray)) /// 69 | (scatteri 12 40 , m(none) mlabc(gray)) /// 70 | , /// Design options 71 | legend(r(1) on order(1 "Private Non-MBBS" 2 "Private MBBS" 3 "Public MBBS")) /// 72 | xtit("Minutes per Patient {&rarr}") ytit("Patients per Provider Day") /// 73 | xlab(5 ":05" 10 ":10" 15 ":15" 20 ":20" 25 ":25" 30 ":30+" , notick) /// 74 | legend(region(lc(none) fc(none))) xtit(,placement(left) justification(left)) 75 | 76 | * Have a lovely day! 77 | -------------------------------------------------------------------------------- /Library/boxplot-pctile.html: -------------------------------------------------------------------------------- 1 | /* 2 | Figure: 10-25-50-75-90 percentile box plot 3 | 4 | Data Source: 5 | --------------------- 6 | Das, Jishnu, Liana Woskie, Ruma Rajbhandari, Kamran Abbasi, and Ashish Jha. 7 | “Rethinking assumptions about delivery of healthcare: implications for universal health coverage.” Bmj 361 (2018). 8 | */ 9 | 10 | global graph_opts1 bgcolor(white) graphregion(color(white)) /// 11 | legend(region(lc(none) fc(none))) /// 12 | ylab(,angle(0) nogrid) title(, justification(left) color(black) span pos(17)) subtitle(, justification(left) color(black)) 13 | 14 | use "https://github.com/worldbank/stata-visual-library/raw/master/Library/data/boxplot-pctile.dta" , clear 15 | 16 | collapse (p10) p10=competence_mle (p25) p25=competence_mle (p50) p50=competence_mle /// 17 | (p75) p75=competence_mle (p90) p90=competence_mle /// 18 | , /// 19 | by(provider_cadre country) /// Graph (10-25-50-75-90 pctiles) 20 | 21 | reshape long p, i(provider_cadre country) 22 | 23 | replace country = "Kenya (N = 372)" if regexm(country,"Kenya") 24 | replace country = "Madagascar (N = 588)" if regexm(country,"Madagascar") 25 | replace country = "Nigeria (N = 1,579)" if regexm(country,"Nigeria") 26 | replace country = "Tanzania (N = 224)" if regexm(country,"Tanzania") 27 | replace country = "Uganda (N = 432)" if regexm(country,"Uganda") 28 | 29 | graph box p /// 30 | , /// 31 | hor over(provider_cadre) over(country ) /// 32 | legend(order(0 "Professional Cadre:" 1 "Medical Officer" 2 "Nurse") r(1) symxsize(small) symysize(small) pos(6) ring(1)) /// 33 | asy $graph_opts1 ylab(-1 "-1 SD" 0 "SDI Mean" .553483 "Median" 1 "+1 SD" 2 "+2 SD" 3 "+3 SD", labsize(vsmall)) ytit("") note("") /// 34 | lintensity(.5) yline(.553483 , lc(black) lp(dash)) /// 35 | box(1 , fi(0) lc(maroon) lw(medthick)) box(2, fc(white) lc(navy) lw(medthick)) /// 36 | title ("Percentile Box Plot") 37 | 38 | * Have a lovely day! 39 | -------------------------------------------------------------------------------- /Library/confidence-intervals.html: -------------------------------------------------------------------------------- 1 | /* 2 | Figure: Confidence intervals 3 | 4 | Data Source: 5 | --------------------- 6 | Jishnu Das, Benjamin Daniels, Monisha Ashok, Eun-Young Shim, and Karthik Muralidharan 7 | Two Indias: The structure of primary health care markets in rural Indian villages with implications for policy. 8 | doi: https://doi.org/10.1016/j.socscimed.2020.112799 9 | repo: https://github.com/bbdaniels/ssm-rhcp-2020 10 | 11 | */ 12 | 13 | use "https://github.com/worldbank/stata-visual-library/blob/bbd-graphs/Library/data/confidence-intervals.dta?raw=true" , clear 14 | 15 | // Get graphing points 16 | gen count = 1 17 | collapse (sum) count (mean) mean = theta_mle (sem) sem = theta_mle , by(mbbs statename) 18 | gen ul = mean + 1.96*sem 19 | gen ll = mean - 1.96*sem 20 | 21 | // Set up labelling and ordering 22 | bys statename : egen check = max(mean) 23 | sort check mbbs 24 | gen n = _n 25 | 26 | local x = 0 27 | local y = 0 28 | forv i = 1/`c(N)' { 29 | replace n = n + `x' in `i' 30 | local ++y 31 | if `y' == 2 { 32 | local x = `x' + 4 33 | local y = 0 34 | } 35 | } 36 | 37 | gen pos = -4.5 38 | gen pos2 = n 39 | 40 | // Graph 41 | tw /// 42 | (rcap ll ul n , lw(thin) lc(black) hor) /// 43 | (scatter n mean if mbbs == 0, mc(white) mlc(black) mlw(thin) m(s) msize(med)) /// 44 | (scatter n mean if mbbs == 1, mc(black) m(.) mlw(none) msize(medsmall)) /// 45 | (scatter pos2 pos if mbbs == 1, mlabpos(3) m(none) ml(statename) mlabc(black)) /// 46 | , yscale(off) xlab(-3(1)2, labsize(small)) ysize(6) /// 47 | legend(on size(small) order (2 "Non-MBBS" 3 "MBBS") ring(0) pos(5) c(1)) /// 48 | xtit("{&larr} Average Provider Competence {&rarr}") 49 | 50 | * Have a lovely day! 51 | -------------------------------------------------------------------------------- /Library/content-summary.csv: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/worldbank/stata-visual-library/552f4353761c3d37f8e1f6cbe671ca5271dc67e7/Library/content-summary.csv -------------------------------------------------------------------------------- /Library/data/README.md: -------------------------------------------------------------------------------- 1 | this is a placeholder 2 | -------------------------------------------------------------------------------- /Library/data/bar-better-ci.dta: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/worldbank/stata-visual-library/552f4353761c3d37f8e1f6cbe671ca5271dc67e7/Library/data/bar-better-ci.dta -------------------------------------------------------------------------------- /Library/data/bar-better.dta: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/worldbank/stata-visual-library/552f4353761c3d37f8e1f6cbe671ca5271dc67e7/Library/data/bar-better.dta -------------------------------------------------------------------------------- /Library/data/bar-counts.dta: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/worldbank/stata-visual-library/552f4353761c3d37f8e1f6cbe671ca5271dc67e7/Library/data/bar-counts.dta -------------------------------------------------------------------------------- /Library/data/bar-custombar.dta: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/worldbank/stata-visual-library/552f4353761c3d37f8e1f6cbe671ca5271dc67e7/Library/data/bar-custombar.dta -------------------------------------------------------------------------------- /Library/data/bar-over.dta: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/worldbank/stata-visual-library/552f4353761c3d37f8e1f6cbe671ca5271dc67e7/Library/data/bar-over.dta -------------------------------------------------------------------------------- /Library/data/bar-stack-by.dta: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/worldbank/stata-visual-library/552f4353761c3d37f8e1f6cbe671ca5271dc67e7/Library/data/bar-stack-by.dta -------------------------------------------------------------------------------- /Library/data/bar-stack-cat.dta: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/worldbank/stata-visual-library/552f4353761c3d37f8e1f6cbe671ca5271dc67e7/Library/data/bar-stack-cat.dta -------------------------------------------------------------------------------- /Library/data/bar-two-axes.dta: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/worldbank/stata-visual-library/552f4353761c3d37f8e1f6cbe671ca5271dc67e7/Library/data/bar-two-axes.dta -------------------------------------------------------------------------------- /Library/data/bar-weightab.dta: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/worldbank/stata-visual-library/552f4353761c3d37f8e1f6cbe671ca5271dc67e7/Library/data/bar-weightab.dta -------------------------------------------------------------------------------- /Library/data/binned-scatter.dta: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/worldbank/stata-visual-library/552f4353761c3d37f8e1f6cbe671ca5271dc67e7/Library/data/binned-scatter.dta -------------------------------------------------------------------------------- /Library/data/boxplot-pctile.dta: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/worldbank/stata-visual-library/552f4353761c3d37f8e1f6cbe671ca5271dc67e7/Library/data/boxplot-pctile.dta -------------------------------------------------------------------------------- /Library/data/confidence-intervals.dta: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/worldbank/stata-visual-library/552f4353761c3d37f8e1f6cbe671ca5271dc67e7/Library/data/confidence-intervals.dta -------------------------------------------------------------------------------- /Library/data/density-av.dta: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/worldbank/stata-visual-library/552f4353761c3d37f8e1f6cbe671ca5271dc67e7/Library/data/density-av.dta -------------------------------------------------------------------------------- /Library/data/density-data.dta: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/worldbank/stata-visual-library/552f4353761c3d37f8e1f6cbe671ca5271dc67e7/Library/data/density-data.dta -------------------------------------------------------------------------------- /Library/data/density-shaded.dta: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/worldbank/stata-visual-library/552f4353761c3d37f8e1f6cbe671ca5271dc67e7/Library/data/density-shaded.dta -------------------------------------------------------------------------------- /Library/data/density-shaded.dta.dta: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/worldbank/stata-visual-library/552f4353761c3d37f8e1f6cbe671ca5271dc67e7/Library/data/density-shaded.dta.dta -------------------------------------------------------------------------------- /Library/data/dot-summary.dta: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/worldbank/stata-visual-library/552f4353761c3d37f8e1f6cbe671ca5271dc67e7/Library/data/dot-summary.dta -------------------------------------------------------------------------------- /Library/data/eventstudy-prepost.dta: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/worldbank/stata-visual-library/552f4353761c3d37f8e1f6cbe671ca5271dc67e7/Library/data/eventstudy-prepost.dta -------------------------------------------------------------------------------- /Library/data/line-fit-text.dta: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/worldbank/stata-visual-library/552f4353761c3d37f8e1f6cbe671ca5271dc67e7/Library/data/line-fit-text.dta -------------------------------------------------------------------------------- /Library/data/reg-chartable.dta: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/worldbank/stata-visual-library/552f4353761c3d37f8e1f6cbe671ca5271dc67e7/Library/data/reg-chartable.dta -------------------------------------------------------------------------------- /Library/data/reg-models.dta: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/worldbank/stata-visual-library/552f4353761c3d37f8e1f6cbe671ca5271dc67e7/Library/data/reg-models.dta -------------------------------------------------------------------------------- /Library/data/reg-panels.dta: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/worldbank/stata-visual-library/552f4353761c3d37f8e1f6cbe671ca5271dc67e7/Library/data/reg-panels.dta -------------------------------------------------------------------------------- /Library/data/regression-fit.dta: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/worldbank/stata-visual-library/552f4353761c3d37f8e1f6cbe671ca5271dc67e7/Library/data/regression-fit.dta -------------------------------------------------------------------------------- /Library/data/scatter-fl-ci.dta: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/worldbank/stata-visual-library/552f4353761c3d37f8e1f6cbe671ca5271dc67e7/Library/data/scatter-fl-ci.dta -------------------------------------------------------------------------------- /Library/data/scatter-fl.dta: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/worldbank/stata-visual-library/552f4353761c3d37f8e1f6cbe671ca5271dc67e7/Library/data/scatter-fl.dta -------------------------------------------------------------------------------- /Library/data/scatter-poly-ci.dta: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/worldbank/stata-visual-library/552f4353761c3d37f8e1f6cbe671ca5271dc67e7/Library/data/scatter-poly-ci.dta -------------------------------------------------------------------------------- /Library/data/scatter-strata.dta: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/worldbank/stata-visual-library/552f4353761c3d37f8e1f6cbe671ca5271dc67e7/Library/data/scatter-strata.dta -------------------------------------------------------------------------------- /Library/density-av.html: -------------------------------------------------------------------------------- 1 | /* 2 | Figure: Density plot with mean maker 3 | 4 | Data Source: 5 | --------------------- 6 | This is a mock dataset. 7 | */ 8 | 9 | use "https://github.com/worldbank/stata-visual-library/raw/master/Library/data/density-av.dta", clear 10 | 11 | sum revenue if post == 0 12 | local pre_mean = r(mean) 13 | sum revenue if post == 1 14 | local post_mean = r(mean) 15 | 16 | twoway (kdensity revenue if post == 0, color(gs10)) /// 17 | (kdensity revenue if post == 1, color(emerald)) /// 18 | , /// 19 | xline(`pre_mean', lcolor(gs12) lpattern(dash)) /// 20 | xline(`post_mean', lcolor(eltgreen) lpattern(dash)) /// 21 | legend(order(1 "Pre-treatment" 2 "Post-treatment")) /// 22 | xtitle(Agriculture revenue (BRL thousands)) /// 23 | ytitle(Density) /// 24 | bgcolor (white) graphregion(color(white)) /// 25 | title("Density Plot with Mean Maker", justification(center) color(black) span pos(17)) 26 | 27 | * Have a lovely day! 28 | -------------------------------------------------------------------------------- /Library/density-data.html: -------------------------------------------------------------------------------- 1 | /* 2 | Figure: Density graph with data points 3 | 4 | Data Source: 5 | --------------------- 6 | Das, Jishnu, Liana Woskie, Ruma Rajbhandari, Kamran Abbasi, and Ashish Jha. 7 | “Rethinking assumptions about delivery of healthcare: implications for universal health coverage.” Bmj 361 (2018). 8 | */ 9 | 10 | global graph_opts title(, justification(left) color(black) span pos(17)) /// 11 | graphregion(color(white)) ylab(,angle(0) nogrid notick) xscale(noline) yscale(noline) yline(0 , lc(black)) /// 12 | xtit(,placement(left) justification(left)) legend(region(lc(none) fc(none))) 13 | 14 | global hist_opts ylab(, angle(0) axis(2)) yscale(noline alt axis(2)) /// 15 | ytit(, axis(2)) ytit(, axis(1)) yscale(off axis(2)) yscale(alt) 16 | 17 | use "https://github.com/worldbank/stata-visual-library/raw/master/Library/data/density-data.dta" , clear 18 | 19 | qui su theta_mle 20 | 21 | gen score = theta_mle - `r(min)' 22 | gen bach = roster_6a8 > 4 23 | 24 | twoway (kdensity score if bach == 0 , lp(dash) lc(maroon) yaxis(2)) /// 25 | (kdensity score if bach == 1 , lp(dash) lc(navy) yaxis(2)) /// 26 | (histogram score if bach == 0 , freq w(.1) recast(scatter) msize(small) mc(maroon)) /// 27 | (histogram score if bach == 1 , freq w(.1) recast(scatter) msize(small) mc(navy)) /// 28 | , /// 29 | legend(symxsize(small) /// 30 | order(0 "" 0 "" 0 "{bf: Degree:}" /// 31 | 3 "Intermediate, Undergrad, or Bachelors (N=575)" /// 32 | 4 "Specialist or Masters (N=431)") /// 33 | c(1) pos(11) ring(0)) /// 34 | ${graph_opts} ${hist_opts} /// 35 | xtit("Knowledge Score {&rarr}") xlab(0(1)7) yline(10 20 30 , lc(gs12) lp(dot)) xsize(7) /// 36 | title("Density Graph with data points") 37 | 38 | * Have a lovely day! 39 | -------------------------------------------------------------------------------- /Library/density-shaded.html: -------------------------------------------------------------------------------- 1 | /* 2 | Figure: Shaded k-density functions 3 | 4 | Data Source: 5 | --------------------- 6 | Data Replicated file from: 7 | 8 | 9 | Install Packages (if needed) 10 | ----------------------------- 11 | We need one packages to run this file: akdensity 12 | Please remove "*" from below lines if you have not installed them and would like to install. 13 | */ 14 | * ssc install akdensity 15 | 16 | use "https://github.com/worldbank/stata-visual-library/raw/master/Library/data/density-shaded.dta", replace 17 | 18 | sort beta_ 19 | gen rank = _n 20 | egen p98 = pctile(beta_), p(98) 21 | 22 | sum beta_, det 23 | local mean = round(`r(mean)', .00001) 24 | local median = round(`r(p50)', .00001) 25 | 26 | /// Graph: DISTRIBUTION OF 2SLS COEFFICIENT ESTIMATES USING RANDOMIZED FOOD AID ALLOCATIONS 27 | akdensity0 beta_, gen(x) at(beta_) bwidth(.0005) //akdensity0 comes from the user-written package "akdensity" 28 | 29 | sum beta_, d 30 | twoway area x beta_ if rank>15 & beta_<(`r(p10)'), color(gs14) || /// light shading below 10% 31 | area x beta_ if beta_>`r(p90)' & rank<980, color(gs14) || /// light shading above 90% 32 | area x beta_ if rank>15 & beta_<(`r(p5)'), color(gs9) || /// dark shading below 5% 33 | area x beta_ if beta_>`r(p95)' & rank<980, color(gs9) || /// dark shading above 95% 34 | line x beta_ if rank>15 & rank<980, lcolor(black) || /// kernal density plot 35 | (pcarrowi -20 .00299 310 .00299, lcolor(cranberry) lpattern(dash) msize(zero)) || /// overlaying vertical line where the N&Q coefficient is 36 | (pcarrowi -20 `r(mean)' 310 `r(mean)', lcolor(gs7) lpattern(dash) msize(zero)) || /// overlaying vertical line where the BS mean is 37 | (pcarrowi -20 `r(p50)' 310 `r(p50)', lcolor(gs7) lpattern(dash) msize(zero)), /// overlaying vertical line where the BS median is 38 | legend(off) /// 39 | xtitle("2SLS Coefficient from baseline model" " ") /// 40 | ytitle("Density" " ") /// 41 | xmlabel(`r(p50)' "Median=`median'" `r(mean)' "Mean=`mean'" , angle(45)) /// 42 | ylabel(none) /// 43 | bgcolor(white) graphregion(color(white)) /// 44 | title("Shaded k-density functions", justification(left) color(black) span pos(17)) 45 | 46 | * Have a lovely day! 47 | -------------------------------------------------------------------------------- /Library/do/bar-better-ci.do: -------------------------------------------------------------------------------- 1 | /* 2 | Figure: Horizontal bar plot with grouping of variables, standard error bars, and cross-group comparisons 3 | 4 | Data Source: 5 | --------------------- 6 | 7 | Satyanarayana S, Kwan A, Daniels B, Subbaraman R, McDowell A, Bergkvist S, Das RK, Das V, Das J, Pai M. 8 | Use of standardised patients to assess antibiotic dispensing for tuberculosis by pharmacies in urban India: A cross-sectional study. 9 | The Lancet Infectious Diseases. 2016 Nov 30;16(11):1261-8. 10 | */ 11 | 12 | global pct `" 0 "0%" .25 "25%" .5 "50%" .75 "75%" 1 "100%" "' 13 | 14 | qui do "https://github.com/worldbank/stata-visual-library/raw/master/Library/ado/betterbar.ado" 15 | 16 | use "https://github.com/worldbank/stata-visual-library/raw/master/Library/data/bar-better-ci.dta", clear 17 | 18 | betterbar /// 19 | (dr_3 correct_treatment) /// 20 | (med_b2_any_antibiotic med_b2_any_steroid med_b2_any_antister med_l_any_2 /// 21 | med_b2_any_schedule_h med_b2_any_schedule_h1 med_b2_any_schedule_x med_l_any_1), /// 22 | over(city) xlab($pct) se bin /// 23 | legend(pos(5) ring(0) c(1) symxsize(small) symysize(small)) /// 24 | ysize(7) n barlab(upper) /// 25 | title ("Horizontal Cluster Bar Plot" , justification(left) color(black) span pos(17)) 26 | 27 | * Have a lovely day! 28 | -------------------------------------------------------------------------------- /Library/do/bar-better.do: -------------------------------------------------------------------------------- 1 | /* 2 | Figure: Horizontal bar with multiple variables 3 | 4 | Data Source: 5 | --------------------- 6 | Daniels, Benjamin, Amy Dolinger, Guadalupe Bedoya, Khama Rogo, Ana Goicoechea, Jorge Coarasa, Francis Wafula, 7 | Njeri Mwaura, Redemptar Kimeu, and Jishnu Das. “Use of standardised patients to assess quality of healthcare in Nairobi, 8 | Kenya: a pilot, cross-sectional study with international comparisons.” BMJ global health 2, no. 2 (2017): e000333. 9 | */ 10 | global graph_opts /// 11 | title(, justification(left) color(black) span pos(11)) /// 12 | graphregion(color(white)) /// 13 | ylab(,angle(0) nogrid) /// 14 | xtit(,placement(left) justification(left)) /// 15 | yscale(noline) xscale(noline) /// 16 | legend(region(lc(none) fc(none))) 17 | 18 | global pct `" 0 "0%" .25 "25%" .5 "50%" .75 "75%" 1 "100%" "' 19 | 20 | qui do "https://github.com/worldbank/stata-visual-library/raw/master/Library/ado/betterbar.ado" 21 | 22 | use "https://github.com/worldbank/stata-visual-library/raw/master/Library/data/bar-better.dta" , clear 23 | 24 | betterbar /// 25 | ??_correct checklist refer med_any med_class_any_6 med_class_any_16 /// 26 | , /// 27 | ${graph_opts} /// 28 | over(facility_type) /// 29 | xlab(${pct}) /// 30 | barlab(mean) /// 31 | legend(r(1) symxsize(small) symysize(small)) /// 32 | title("Horizontal Cluster Bar Plot") 33 | 34 | 35 | * Have a lovely day! 36 | -------------------------------------------------------------------------------- /Library/do/bar-counts.do: -------------------------------------------------------------------------------- 1 | /* 2 | Figure: Horizontal bar plot with grouping of variables, standard error bars, and cross-group comparisons 3 | 4 | Data Source: 5 | --------------------- 6 | 7 | Jishnu Das, Benjamin Daniels, Monisha Ashok, Eun-Young Shim, and Karthik Muralidharan 8 | Two Indias: The structure of primary health care markets in rural Indian villages with implications for policy 9 | Social Science & Medicine. Doi: https://doi.org/10.1016/j.socscimed.2020.112799 10 | */ 11 | 12 | use "https://github.com/worldbank/stata-visual-library/blob/bbd-graphs/Library/data/bar-counts.dta?raw=true", clear 13 | 14 | // Create all-India category 15 | expand 2 , gen(false) 16 | replace state_code = 0 if false == 1 17 | lab def state_code 0 "All India" , modify 18 | replace u5mr = 100 if state_code == 0 19 | 20 | // Add U5MR to titles 21 | qui levelsof state_code , local(levels) 22 | foreach state in `levels' { 23 | local theLabel : label (state_code) `state' 24 | qui su u5mr if state_code == `state' 25 | if `state' != 0 lab def state_code `state' "`theLabel' [`r(mean)']" , modify 26 | } 27 | 28 | // Graph 29 | local opts lc(black) lp(solid) lw(vthin) la(center) fc("0 109 219") 30 | local opts2 lc(black) lp(solid) lw(vthin) la(center) fc("146 0 0") 31 | 32 | graph bar (mean) type_?0 type_?1 [pweight = weight_psu] /// 33 | , over(private, gap(*.5) label(labsize(tiny))) /// 34 | over(state_code , gap(*.5) label(labsize(vsmall)) sort((mean) u5mr) ) /// 35 | stack hor yscale(noline) /// 36 | $graph_opts_1 ysize(6) xoverhang /// 37 | ytit("Providers per Village {&rarr}" , placement(left) justification(left)) /// 38 | legend(on span region(lc(none)) ring(1) pos(7) r(2) size(small) symysize(small) symxsize(small) /// 39 | order(13 "Public:" 1 "MBBS" 2 "AYUSH" 3 "Other" 4 "Unknown" /// 40 | 13 "Private:" 5 "MBBS" 6 "AYUSH" 7 "Other" 8 "Unknown") /// 41 | ) /// 42 | bar(1, fi(100) `opts') bar(2, fi(75) `opts') /// 43 | bar(3, fi(50) `opts') bar(4, fi(25) `opts') /// 44 | bar(5, fi(100) `opts2') bar(6, fi(75) `opts2') /// 45 | bar(7, fi(50) `opts2') bar(8, fi(25) `opts2') 46 | 47 | * Have a lovely day! 48 | -------------------------------------------------------------------------------- /Library/do/bar-over.do: -------------------------------------------------------------------------------- 1 | /* 2 | Figures: bar plot of two variables 3 | 4 | Data Source: 5 | --------------------- 6 | Das, Jishnu, Liana Woskie, Ruma Rajbhandari, Kamran Abbasi, and Ashish Jha. 7 | “Rethinking assumptions about delivery of healthcare: implications for universal health coverage.” Bmj 361 (2018). 8 | */ 9 | 10 | global graph_opts1 /// 11 | bgcolor(white) /// 12 | graphregion(color(white)) /// 13 | legend(region(lc(none) fc(none))) /// 14 | ylab(,angle(0) nogrid) /// 15 | title(, justification(center) color(black) span pos(17)) /// 16 | subtitle(, justification(left) color(black)) 17 | 18 | use "https://github.com/worldbank/stata-visual-library/raw/master/Library/data/bar-over.dta" , clear 19 | 20 | graph bar treat_correct /// 21 | , /// 22 | over(type) /// 23 | asy /// 24 | bargap(20) /// 25 | over(study) /// 26 | over(case) /// 27 | nofill /// 28 | blabel(bar, format(%9.2f)) /// 29 | ${graph_opts1} /// 30 | bar(1 , lc(black) lw(thin) fi(100)) /// 31 | bar(2 , lc(black) lw(thin) fi(100)) /// 32 | legend(r(1) /// 33 | order(0 "Measurement:" 1 "Standardized Patient" 2 "Clinical Vignette")) /// 34 | ytit("Providers ordering correct treatment {&rarr}", /// 35 | placement(bottom) /// 36 | justification(left)) /// 37 | ylab(${pct}) /// 38 | title("Bar Plot of Two Variables") 39 | 40 | * Have a lovely day! 41 | -------------------------------------------------------------------------------- /Library/do/bar-sorted.do: -------------------------------------------------------------------------------- 1 | /* 2 | Figure: Sorted bar graph 3 | 4 | Data Source: 5 | --------------------- 6 | 7 | lifeexp from Stata 8 | */ 9 | 10 | global graph_opts1 /// //global set so options can be accessed by other do-files 11 | graphregion(color(white) lc(white) la(center)) /// <- remove la(center) for Stata < 15 12 | 13 | 14 | *load data 15 | 16 | sysuse lifeexp 17 | 18 | qui su lexp, de //calculate summary statistics to get 75th percentile 19 | 20 | /* Graph horizontal bars that are sorted in descending order; population growth 21 | by country with >75th percentile life expectancy */ 22 | 23 | graph hbar popgrowth if lexp > `r(p75)', /// 24 | over(country, sort(1) descending) /// sort the bars by shrinking height 25 | ${graph_opts1} /// 26 | ytitle("Average Annual Percent Growth in Population") /// 27 | scale(*.75) bar(1, lc(black) lw(thin) fc(emerald)) //scale resizes text and lines so it's not as crowded 28 | 29 | *Have a lovely day!* -------------------------------------------------------------------------------- /Library/do/bar-stack-by.do: -------------------------------------------------------------------------------- 1 | /* 2 | Figure: Stack bar graph by two variables (Drug use by referral decisions for two standardised patient cases) 3 | 4 | Data Source: 5 | --------------------- 6 | 7 | Satyanarayana S, Kwan A, Daniels B, Subbaraman R, McDowell A, Bergkvist S, Das RK, Das V, Das J, Pai M. 8 | Use of standardised patients to assess antibiotic dispensing for tuberculosis by pharmacies in urban India: 9 | A cross-sectional study. The Lancet Infectious Diseases. 2016 Nov 30;16(11):1261-8. 10 | 11 | 12 | Install Packages (if needed) 13 | ----------------------------- 14 | We need one packages to run this file: grc1leg 15 | Please remove "*" from below lines if you have not installed it and would like to install. 16 | */ 17 | 18 | * net install grc1leg, from(http://www.stata.com/users/vwiggins) 19 | 20 | global graph_opts1 bgcolor(white) graphregion(color(white)) legend(region(lc(none) fc(none))) ylab(,angle(0) nogrid) subtitle(, justification(left) color(black) span pos(11)) title(, justification(center) color(black) span pos(17)) 21 | global pct `" 0 "0%" .25 "25%" .5 "50%" .75 "75%" 1 "100%" "' 22 | 23 | use "https://github.com/worldbank/stata-visual-library/raw/master/Library/data/bar-stack-by.dta", clear 24 | 25 | graph bar med_b2_antister_cat?? /// 26 | if dr_3 == 1 /// 27 | , /// 28 | stack over(checkgroup) nofill /// 29 | ylab(${pct}) /// 30 | legend(order(5 "No Medication" /// 31 | 4 "Antibiotic and Steroid" /// 32 | 3 "Antibiotic" /// 33 | 2 "Steroid" /// 34 | 1 "No Antibiotic or Steroid") /// 35 | c(1) pos(3) /// 36 | symxsize(small) symysize(small) size(small)) /// 37 | ${graph_opts1} /// 38 | bar(5, color(white) lc(black) lp(solid) lw(thin)) /// 39 | bar(1,lw(thin) lc(black)) bar(2,lw(thin) lc(black)) /// 40 | bar(3,lw(thin) lc(black)) bar(4,lw(thin) lc(black)) /// 41 | subtitle("Referral", color(black) justification(center) pos(12)) /// 42 | name(figure_1) 43 | 44 | graph bar med_b2_antister_cat?? /// 45 | if dr_3 == 0 /// 46 | , /// 47 | stack over(checkgroup) nofill /// 48 | ylab(${pct}) /// 49 | legend(order(5 "No Medication" /// 50 | 4 "Antibiotic and Steroid" /// 51 | 3 "Antibiotic" /// 52 | 2 "Steroid" /// 53 | 1 "No Antibiotic or Steroid") /// 54 | c(1) pos(3) /// 55 | symxsize(small) symysize(small) size(small)) /// 56 | ${graph_opts1} /// 57 | bar(5, color(white) lc(black) lp(solid) lw(thin)) /// 58 | bar(1,lw(thin) lc(black)) /// 59 | bar(2,lw(thin) lc(black)) /// 60 | bar(3,lw(thin) lc(black)) /// 61 | bar(4,lw(thin) lc(black)) /// 62 | subtitle("No Referral", color(black) justification(center) pos(12)) /// 63 | name(figure_2) 64 | 65 | grc1leg figure_2 figure_1 /// 66 | , /// 67 | title ("Stack Bar Chart") /// 68 | pos(3) /// 69 | graphregion(color(white)) /// 70 | xsize(7) /// 71 | rows(1) /// 72 | leg(figure_2) 73 | 74 | * Have a lovely day! 75 | -------------------------------------------------------------------------------- /Library/do/bar-stack-cat.do: -------------------------------------------------------------------------------- 1 | /* 2 | Figure: horizontal stack bar plot 3 | 4 | Data Source: 5 | --------------------- 6 | Kwan, Ada, Benjamin Daniels, Vaibhav Saria, Srinath Satyanarayana, Ramnath Subbaraman, Andrew McDowell, 7 | Sofi Bergkvist et al. “Variations in the quality of tuberculosis care in urban India: a cross-sectional, 8 | standardized patient study in two cities.” PLoS medicine 15, no. 9 (2018): e1002653. 9 | 10 | */ 11 | global graph_opts1 /// 12 | graphregion(color(white) lc(white) la(center)) /// <- remove la(center) for Stata < 15 13 | ylab(,angle(0) nogrid) /// 14 | yscale(noline) legend(region(lc(none) fc(none))) 15 | 16 | global pct `" 0 "0%" .25 "25%" .5 "50%" .75 "75%" 1 "100%" "' 17 | 18 | use "https://github.com/worldbank/stata-visual-library/raw/master/Library/data/bar-stack-cat.dta" , clear 19 | 20 | local x = 0 21 | qui foreach var of varlist /// 22 | correct treat_cxr re_3 re_4 treat_refer /// 23 | med_any med_l_any_1 med_l_any_2 med_l_any_3 med_k_any_9 { 24 | 25 | mean `var' [pweight = weight_city] 26 | mat a = e(b) 27 | local mean = a[1,1] 28 | local mean = string(round(100*`mean',0)) 29 | local mean = substr("`mean'",1,strpos("`mean'",".")+1) 30 | 31 | local ++x 32 | local theLabel : var label `var' 33 | local theLabels `" `theLabels' `x' "`theLabel'" "' // [`mean'%] 34 | 35 | cap mat drop theResult 36 | reg `var' i.city [pweight = weight_city] 37 | local theR21 = `e(r2)' 38 | mat theResult = nullmat(theResult) , [`theR21'] 39 | 40 | reg `var' i.city i.case [pweight = weight_city] 41 | local theR22 = `e(r2)' - `theR21' 42 | mat theResult = nullmat(theResult) , [`theR22'] 43 | 44 | reg `var' i.city i.case i.type_formal [pweight = weight_city] 45 | local theR23 = `e(r2)' - `theR21' - `theR22' 46 | mat theResult = nullmat(theResult) , [`theR23'] 47 | 48 | reg `var' i.city i.case i.type_formal i.sp_city_id [pweight = weight_city] 49 | local theR24 = `e(r2)' - `theR21' - `theR22' - `theR23' 50 | mat theResult = nullmat(theResult) , [`theR24'] 51 | 52 | reg `var' i.city i.case i.type_formal i.sp_city_id i.sp_city_mbbs [pweight = weight_city] 53 | local theR25 = `e(r2)' - `theR21' - `theR22' - `theR23' - `theR24' 54 | mat theResult = nullmat(theResult) , [`theR25'] 55 | 56 | mean `var' [pweight = weight_city] 57 | mat a = e(b) 58 | local mean = a[1,1] 59 | mat theResult = nullmat(theResult) , [`mean'] 60 | 61 | mat theResults = nullmat(theResults) \ theResult 62 | matlist theResults 63 | 64 | } 65 | 66 | clear 67 | svmat theResults 68 | gen n = _n 69 | label def n `theLabels' 70 | label val n n 71 | 72 | graph bar (sum) theResults1 theResults2 theResults3 theResults4 theResults5 /// 73 | , /// 74 | ylab($pct) /// 75 | ${graph_opts1} /// 76 | title("Horizontal Stack Bar Chart", justification(left) color(black) span pos(17)) /// 77 | hor stack over(n) xsize(6) /// 78 | bar(1, lc(black) lw(thin)) /// 79 | bar(2, lc(black) lw(thin)) /// 80 | bar(3, lc(black) lw(thin)) /// 81 | bar(4, fc(black) lc(black) lw(thin)) /// 82 | bar(5, fc(gs12) lc(black) lw(thin)) /// 83 | legend(pos(5) ring(0) c(1) symxsize(small) symysize(small) /// 84 | order(6 "Variance Explained By:" /// 85 | 1 "City Setting" /// 86 | 2 "Case Scenario" /// 87 | 3 "MBBS Degree" /// 88 | 4 "All SP Characteristics" /// 89 | 5 "Full Interaction Model")) 90 | 91 | * Have a lovely day! 92 | -------------------------------------------------------------------------------- /Library/do/bar-two-axes.do: -------------------------------------------------------------------------------- 1 | /* 2 | Figure: combined bar plots with two axex 3 | 4 | Data Source: 5 | --------------------- 6 | Mock data and code were based in 7 | Christian, Paul, and Brian Dillon. 2018. “Growing and Learning When Consumption Is Seasonal: 8 | Long-Term Evidence From Tanzania.” Demography 55 (3): 1091–1118. doi:10.1007/s13524-018-0669-4. 9 | */ 10 | 11 | use "https://github.com/worldbank/stata-visual-library/raw/master/Library/data/bar-two-axes.dta", clear 12 | 13 | gen x = int1mo+.5 /// Adjust variable for bar position 14 | 15 | foreach foodGroup in animal fruit grain veg starch processed_sugar { 16 | /// Create invidual graphs using a loop 17 | if "`foodGroup'" == "animal" local graphTitle Animal Sourced 18 | if "`foodGroup'" == "fruit" local graphTitle Fruit 19 | if "`foodGroup'" == "grain" local graphTitle Grain 20 | if "`foodGroup'" == "veg" local graphTitle Vegetables 21 | if "`foodGroup'" == "starch" local graphTitle Starchy Foods 22 | if "`foodGroup'" == "processed_sugar" local graphTitle Processed/Sugar 23 | 24 | twoway bar number_group x if food_group=="`foodGroup'", /// 25 | yaxis(1) ytitle("Avg. Number of Foods from" "Group Consumed Last Month", axis(1)) /// 26 | barwidth(.9) fintensity(inten0) lcolor(black) /// 27 | xlabel(0 "0" 3 "3" 6 "6" 9 "9" 12 "12") /// 28 | ylabel(0 "0" 1 "1" 2 "2" 3 "3", axis(1)) || /// 29 | line total_exp int1mo if food_group=="`foodGroup'", /// 30 | yaxis(2) ytitle("Total Value of Exp." "1000 Real Tz Sh.", axis(2)) /// 31 | ylabel(0 "0" 500 "500" 1000 "1000" 1500 "1500" 2000 "2000" 2500 "2500", axis(2)) /// 32 | xlabel(3 "3" 6 "6" 9 "9" 12 "12") lwidth(1.2) /// 33 | title("`graphTitle'") xtitle("Month of Interview") /// 34 | graphregion(color(white)) bgcolor(white) /// 35 | legend(off) /// 36 | name("`foodGroup'") 37 | 38 | } 39 | 40 | graph combine starch animal fruit grain processed_sugar veg, /// 41 | title("Combined Bar Plot with Dual Axes", justification(center) color(black) span pos(17)) /// 42 | graphregion( color(white)) plotregion(color(white)) 43 | 44 | 45 | * Have a lovely day! 46 | -------------------------------------------------------------------------------- /Library/do/bar-weightab.do: -------------------------------------------------------------------------------- 1 | /* 2 | Figure: Side by side horizontal bar plot (Outcomes by City & Case) using weightab 3 | 4 | Data Source: 5 | --------------------- 6 | 7 | Kwan, Ada, Benjamin Daniels, Vaibhav Saria, Srinath Satyanarayana, Ramnath Subbaraman, Andrew McDowell, Sofi Bergkvist et al. 8 | “Variations in the quality of tuberculosis care in urban India: a cross-sectional, 9 | standardized patient study in two cities.” PLoS medicine 15, no. 9 (2018): e1002653. 10 | */ 11 | 12 | global graph_opts /// 13 | title(, justification(left) color(black) span pos(11)) /// 14 | graphregion(color(white) lc(white) lw(med) la(center)) /// <- remove la(center) for Stata < 15 15 | ylab(,angle(0) nogrid) xtit(,placement(left) justification(left)) /// 16 | yscale(noline) xscale(noline) legend(region(lc(none) fc(none))) 17 | 18 | local opts lw(thin) lc(white) la(center) 19 | 20 | label def case 1 "Case 1" 2 "Case 2" 3 "Case 3" 4 "Case 4" , modify 21 | 22 | qui do "https://github.com/worldbank/stata-visual-library/raw/master/Library/ado/weightab.ado" 23 | 24 | use "https://github.com/worldbank/stata-visual-library/raw/master/Library/data/bar-weightab.dta" , clear 25 | 26 | weightab /// Create Figure 1 27 | correct treat_cxr re_3 re_4 treat_refer t_12 /// 28 | med_any med_l_any_1 med_l_any_2 med_l_any_3 med_k_any_9 /// 29 | if city == 2 /// 30 | [pweight = weight_city] /// 31 | , /// 32 | ${graph_opts} /// 33 | barlab /// 34 | barlook(1 `opts' fi(100)) /// 35 | title("Patna") /// 36 | over(case) /// 37 | graph /// 38 | legend(off) /// 39 | xlab(${pct}) /// 40 | name(Fig_1_1) 41 | 42 | weightab /// Create Figure 2 43 | correct treat_cxr re_3 re_4 treat_refer t_12 /// 44 | med_any med_l_any_1 med_l_any_2 med_l_any_3 med_k_any_9 /// 45 | if city == 3 /// 46 | [pweight = weight_city] /// 47 | , /// 48 | ${graph_opts} /// 49 | barlab /// 50 | barlook(1 `opts' fi(100)) /// 51 | title("Mumbai") /// 52 | over(case) /// 53 | graph /// 54 | legend(pos(5) ring(0) c(1) symxsize(small) symysize(small)) /// 55 | xlab(${pct}) /// 56 | name(Fig_1_2) 57 | 58 | graph combine Fig_1_1 Fig_1_2 /// Combine Figure 1 and 2 59 | , /// 60 | title("Side by Side Horizontal Barplot using weightab", justification(left) color(black) span pos(17)) /// 61 | ${comb_opts} /// 62 | xsize(7) r(1) 63 | 64 | * Have a lovely day! 65 | -------------------------------------------------------------------------------- /Library/do/binned-scatter.do: -------------------------------------------------------------------------------- 1 | /* 2 | Figure: Binned scatter plot 3 | 4 | Data Source: 5 | --------------------- 6 | Jishnu Das, Benjamin Daniels, Monisha Ashok, Eun-Young Shim, and Karthik Muralidharan 7 | Two Indias: The structure of primary health care markets in rural Indian villages with implications for policy. 8 | doi: https://doi.org/10.1016/j.socscimed.2020.112799 9 | repo: https://github.com/bbdaniels/ssm-rhcp-2020 10 | */ 11 | 12 | use "https://github.com/worldbank/stata-visual-library/blob/bbd-graphs/Library/data/binned-scatter.dta?raw=true" , clear 13 | 14 | count 15 | recode s1q15 (-99 = .) 16 | count if s2q15 != . & s2q16 != . 17 | 18 | // Adjust number of patients for public clinics 19 | egen group = group(private mbbs) , label 20 | replace group = 2 if group == . 21 | bys finclinid: gen n = _N 22 | bys stateid finclinid_new: gen ndocs = _N 23 | replace patients = patients/ndocs if public == 1 24 | gen check = patients 25 | drop if (check > 120 | s2q16 == 0) 26 | 27 | // bin minutes per patient and calculate hours per day 28 | recode s2q16 (1/5 = 5)(6/10 = 10)(11/15 = 15)(16/20 = 20)(26/max=30) , gen(minpp) 29 | gen hours = check*s2q16/60 30 | gen pct = hours / 6 31 | mean hours pct patients s2q16 [pweight = weight_psu] , over(group) // average utilization 32 | 33 | // Graph 34 | replace minpp = minpp+1 if group == 1 // Public MBBS 35 | replace minpp = minpp-1 if group == 2 // Private non-MBBS 36 | 37 | local opts lc(gray) lw(thin) 38 | 39 | isid uid , sort 40 | version 13 41 | 42 | gen blank = . 43 | 44 | tw /// 45 | /// Invisible cheaters for legend 46 | (scatter blank blank in 1 , m(.) mc(black) msize(*2)) /// 47 | (scatter blank blank in 1 , m(T) mc("0 109 219") msize(*4)) /// 48 | (scatter blank blank in 1 , m(S) mc("146 0 0") msize(*4)) /// 49 | /// Actual graph points 50 | (scatter check minpp if private == 1 & mbbs == 0, /// 51 | jitter(2) jitterseed(382375) m(.) mc("0 0 0") msize(*.1)) /// 52 | (scatter check minpp if private == 1 & mbbs == 1, /// 53 | jitter(2) jitterseed(382375) m(T) mc("0 109 219") msize(*.4)) /// 54 | (scatter check minpp if private == 0 & mbbs == 1, /// 55 | jitter(2) jitterseed(382375) m(S) mc("146 0 0") msize(*.4)) /// 56 | /// Reference line 57 | (function 72, range(3 7.5) `opts') /// 58 | (pci 36 7.5 72 7.5 , `opts') /// 59 | (function 36, range(7.5 12.5) `opts') /// 60 | (pci 36 12.5 24 12.5 , `opts') /// 61 | (function 24, range(12.5 17.5) `opts') /// 62 | (pci 24 17.5 18 17.5 , `opts') /// 63 | (function 18, range(17.5 22.5) `opts') /// 64 | (pci 18 22.5 14.4 22.5 , `opts') /// 65 | (function 14.4, range(22.5 27.5) `opts') /// 66 | (pci 14.4 27.5 12 27.5 , `opts') /// 67 | (function 12, range(27.5 32) `opts') /// 68 | (scatteri 12 32 "6 Hour Workday" , m(none) mlabc(gray)) /// 69 | (scatteri 12 40 , m(none) mlabc(gray)) /// 70 | , /// Design options 71 | legend(r(1) on order(1 "Private Non-MBBS" 2 "Private MBBS" 3 "Public MBBS")) /// 72 | xtit("Minutes per Patient {&rarr}") ytit("Patients per Provider Day") /// 73 | xlab(5 ":05" 10 ":10" 15 ":15" 20 ":20" 25 ":25" 30 ":30+" , notick) /// 74 | legend(region(lc(none) fc(none))) xtit(,placement(left) justification(left)) 75 | 76 | * Have a lovely day! 77 | -------------------------------------------------------------------------------- /Library/do/boxplot-pctile.do: -------------------------------------------------------------------------------- 1 | /* 2 | Figure: 10-25-50-75-90 percentile box plot 3 | 4 | Data Source: 5 | --------------------- 6 | Das, Jishnu, Liana Woskie, Ruma Rajbhandari, Kamran Abbasi, and Ashish Jha. 7 | “Rethinking assumptions about delivery of healthcare: implications for universal health coverage.” Bmj 361 (2018). 8 | */ 9 | 10 | global graph_opts1 bgcolor(white) graphregion(color(white)) /// 11 | legend(region(lc(none) fc(none))) /// 12 | ylab(,angle(0) nogrid) title(, justification(left) color(black) span pos(17)) subtitle(, justification(left) color(black)) 13 | 14 | use "https://github.com/worldbank/stata-visual-library/raw/master/Library/data/boxplot-pctile.dta" , clear 15 | 16 | collapse (p10) p10=competence_mle (p25) p25=competence_mle (p50) p50=competence_mle /// 17 | (p75) p75=competence_mle (p90) p90=competence_mle /// 18 | , /// 19 | by(provider_cadre country) /// Graph (10-25-50-75-90 pctiles) 20 | 21 | reshape long p, i(provider_cadre country) 22 | 23 | replace country = "Kenya (N = 372)" if regexm(country,"Kenya") 24 | replace country = "Madagascar (N = 588)" if regexm(country,"Madagascar") 25 | replace country = "Nigeria (N = 1,579)" if regexm(country,"Nigeria") 26 | replace country = "Tanzania (N = 224)" if regexm(country,"Tanzania") 27 | replace country = "Uganda (N = 432)" if regexm(country,"Uganda") 28 | 29 | graph box p /// 30 | , /// 31 | hor over(provider_cadre) over(country ) /// 32 | legend(order(0 "Professional Cadre:" 1 "Medical Officer" 2 "Nurse") r(1) symxsize(small) symysize(small) pos(6) ring(1)) /// 33 | asy $graph_opts1 ylab(-1 "-1 SD" 0 "SDI Mean" .553483 "Median" 1 "+1 SD" 2 "+2 SD" 3 "+3 SD", labsize(vsmall)) ytit("") note("") /// 34 | lintensity(.5) yline(.553483 , lc(black) lp(dash)) /// 35 | box(1 , fi(0) lc(maroon) lw(medthick)) box(2, fc(white) lc(navy) lw(medthick)) /// 36 | title ("Percentile Box Plot") 37 | 38 | * Have a lovely day! 39 | -------------------------------------------------------------------------------- /Library/do/confidence-intervals.do: -------------------------------------------------------------------------------- 1 | /* 2 | Figure: Confidence intervals 3 | 4 | Data Source: 5 | --------------------- 6 | Jishnu Das, Benjamin Daniels, Monisha Ashok, Eun-Young Shim, and Karthik Muralidharan 7 | Two Indias: The structure of primary health care markets in rural Indian villages with implications for policy. 8 | doi: https://doi.org/10.1016/j.socscimed.2020.112799 9 | repo: https://github.com/bbdaniels/ssm-rhcp-2020 10 | 11 | */ 12 | 13 | use "https://github.com/worldbank/stata-visual-library/blob/bbd-graphs/Library/data/confidence-intervals.dta?raw=true" , clear 14 | 15 | // Get graphing points 16 | gen count = 1 17 | collapse (sum) count (mean) mean = theta_mle (sem) sem = theta_mle , by(mbbs statename) 18 | gen ul = mean + 1.96*sem 19 | gen ll = mean - 1.96*sem 20 | 21 | // Set up labelling and ordering 22 | bys statename : egen check = max(mean) 23 | sort check mbbs 24 | gen n = _n 25 | 26 | local x = 0 27 | local y = 0 28 | forv i = 1/`c(N)' { 29 | replace n = n + `x' in `i' 30 | local ++y 31 | if `y' == 2 { 32 | local x = `x' + 4 33 | local y = 0 34 | } 35 | } 36 | 37 | gen pos = -4.5 38 | gen pos2 = n 39 | 40 | // Graph 41 | tw /// 42 | (rcap ll ul n , lw(thin) lc(black) hor) /// 43 | (scatter n mean if mbbs == 0, mc(white) mlc(black) mlw(thin) m(s) msize(med)) /// 44 | (scatter n mean if mbbs == 1, mc(black) m(.) mlw(none) msize(medsmall)) /// 45 | (scatter pos2 pos if mbbs == 1, mlabpos(3) m(none) ml(statename) mlabc(black)) /// 46 | , yscale(off) xlab(-3(1)2, labsize(small)) ysize(6) /// 47 | legend(on size(small) order (2 "Non-MBBS" 3 "MBBS") ring(0) pos(5) c(1)) /// 48 | xtit("{&larr} Average Provider Competence {&rarr}") 49 | 50 | * Have a lovely day! 51 | -------------------------------------------------------------------------------- /Library/do/density-av.do: -------------------------------------------------------------------------------- 1 | /* 2 | Figure: Density plot with mean maker 3 | 4 | Data Source: 5 | --------------------- 6 | This is a mock dataset. 7 | */ 8 | 9 | use "https://github.com/worldbank/stata-visual-library/raw/master/Library/data/density-av.dta", clear 10 | 11 | sum revenue if post == 0 12 | local pre_mean = r(mean) 13 | sum revenue if post == 1 14 | local post_mean = r(mean) 15 | 16 | twoway (kdensity revenue if post == 0, color(gs10)) /// 17 | (kdensity revenue if post == 1, color(emerald)) /// 18 | , /// 19 | xline(`pre_mean', lcolor(gs12) lpattern(dash)) /// 20 | xline(`post_mean', lcolor(eltgreen) lpattern(dash)) /// 21 | legend(order(1 "Pre-treatment" 2 "Post-treatment")) /// 22 | xtitle(Agriculture revenue (BRL thousands)) /// 23 | ytitle(Density) /// 24 | bgcolor (white) graphregion(color(white)) /// 25 | title("Density Plot with Mean Maker", justification(center) color(black) span pos(17)) 26 | 27 | * Have a lovely day! 28 | -------------------------------------------------------------------------------- /Library/do/density-data.do: -------------------------------------------------------------------------------- 1 | /* 2 | Figure: Density graph with data points 3 | 4 | Data Source: 5 | --------------------- 6 | Das, Jishnu, Liana Woskie, Ruma Rajbhandari, Kamran Abbasi, and Ashish Jha. 7 | “Rethinking assumptions about delivery of healthcare: implications for universal health coverage.” Bmj 361 (2018). 8 | */ 9 | 10 | global graph_opts title(, justification(left) color(black) span pos(17)) /// 11 | graphregion(color(white)) ylab(,angle(0) nogrid notick) xscale(noline) yscale(noline) yline(0 , lc(black)) /// 12 | xtit(,placement(left) justification(left)) legend(region(lc(none) fc(none))) 13 | 14 | global hist_opts ylab(, angle(0) axis(2)) yscale(noline alt axis(2)) /// 15 | ytit(, axis(2)) ytit(, axis(1)) yscale(off axis(2)) yscale(alt) 16 | 17 | use "https://github.com/worldbank/stata-visual-library/raw/master/Library/data/density-data.dta" , clear 18 | 19 | qui su theta_mle 20 | 21 | gen score = theta_mle - `r(min)' 22 | gen bach = roster_6a8 > 4 23 | 24 | twoway (kdensity score if bach == 0 , lp(dash) lc(maroon) yaxis(2)) /// 25 | (kdensity score if bach == 1 , lp(dash) lc(navy) yaxis(2)) /// 26 | (histogram score if bach == 0 , freq w(.1) recast(scatter) msize(small) mc(maroon)) /// 27 | (histogram score if bach == 1 , freq w(.1) recast(scatter) msize(small) mc(navy)) /// 28 | , /// 29 | legend(symxsize(small) /// 30 | order(0 "" 0 "" 0 "{bf: Degree:}" /// 31 | 3 "Intermediate, Undergrad, or Bachelors (N=575)" /// 32 | 4 "Specialist or Masters (N=431)") /// 33 | c(1) pos(11) ring(0)) /// 34 | ${graph_opts} ${hist_opts} /// 35 | xtit("Knowledge Score {&rarr}") xlab(0(1)7) yline(10 20 30 , lc(gs12) lp(dot)) xsize(7) /// 36 | title("Density Graph with data points") 37 | 38 | * Have a lovely day! 39 | -------------------------------------------------------------------------------- /Library/do/density-shaded.do: -------------------------------------------------------------------------------- 1 | /* 2 | Figure: Shaded k-density functions 3 | 4 | Data Source: 5 | --------------------- 6 | Data Replicated file from: 7 | 8 | 9 | Install Packages (if needed) 10 | ----------------------------- 11 | We need one packages to run this file: akdensity 12 | Please remove "*" from below lines if you have not installed them and would like to install. 13 | */ 14 | * ssc install akdensity 15 | 16 | use "https://github.com/worldbank/stata-visual-library/raw/master/Library/data/density-shaded.dta", replace 17 | 18 | sort beta_ 19 | gen rank = _n 20 | egen p98 = pctile(beta_), p(98) 21 | 22 | sum beta_, det 23 | local mean = round(`r(mean)', .00001) 24 | local median = round(`r(p50)', .00001) 25 | 26 | /// Graph: DISTRIBUTION OF 2SLS COEFFICIENT ESTIMATES USING RANDOMIZED FOOD AID ALLOCATIONS 27 | akdensity0 beta_, gen(x) at(beta_) bwidth(.0005) //akdensity0 comes from the user-written package "akdensity" 28 | 29 | sum beta_, d 30 | twoway area x beta_ if rank>15 & beta_<(`r(p10)'), color(gs14) || /// light shading below 10% 31 | area x beta_ if beta_>`r(p90)' & rank<980, color(gs14) || /// light shading above 90% 32 | area x beta_ if rank>15 & beta_<(`r(p5)'), color(gs9) || /// dark shading below 5% 33 | area x beta_ if beta_>`r(p95)' & rank<980, color(gs9) || /// dark shading above 95% 34 | line x beta_ if rank>15 & rank<980, lcolor(black) || /// kernal density plot 35 | (pcarrowi -20 .00299 310 .00299, lcolor(cranberry) lpattern(dash) msize(zero)) || /// overlaying vertical line where the N&Q coefficient is 36 | (pcarrowi -20 `r(mean)' 310 `r(mean)', lcolor(gs7) lpattern(dash) msize(zero)) || /// overlaying vertical line where the BS mean is 37 | (pcarrowi -20 `r(p50)' 310 `r(p50)', lcolor(gs7) lpattern(dash) msize(zero)), /// overlaying vertical line where the BS median is 38 | legend(off) /// 39 | xtitle("2SLS Coefficient from baseline model" " ") /// 40 | ytitle("Density" " ") /// 41 | xmlabel(`r(p50)' "Median=`median'" `r(mean)' "Mean=`mean'" , angle(45)) /// 42 | ylabel(none) /// 43 | bgcolor(white) graphregion(color(white)) /// 44 | title("Shaded k-density functions", justification(left) color(black) span pos(17)) 45 | 46 | * Have a lovely day! 47 | -------------------------------------------------------------------------------- /Library/do/dot-summary.do: -------------------------------------------------------------------------------- 1 | /* 2 | Figure: Binned scatter plot 3 | 4 | Data Source: 5 | --------------------- 6 | Jishnu Das, Benjamin Daniels, Monisha Ashok, Eun-Young Shim, and Karthik Muralidharan 7 | Two Indias: The structure of primary health care markets in rural Indian villages with implications for policy. 8 | doi: https://doi.org/10.1016/j.socscimed.2020.112799 9 | repo: https://github.com/bbdaniels/ssm-rhcp-2020 10 | */ 11 | 12 | use "https://github.com/worldbank/stata-visual-library/blob/bbd-graphs/Library/data/dot-summary.dta?raw=true" , clear 13 | 14 | egen total = rsum(type_?) 15 | gen any = (total>0) 16 | 17 | collapse (max) any regsim_? (mean) weight_psu , by(state_code villid) fast 18 | collapse (mean) any (mean) regsim_? , by(state_code) 19 | 20 | forvalues i = 1/3 { 21 | replace regsim_`i' = regsim_`i'*any 22 | } 23 | 24 | egen check = rank(regsim_3) , unique 25 | sort check 26 | decode state_code , gen(state) 27 | 28 | qui count 29 | forvalues i = 1/`r(N)' { 30 | local theState = state[`i'] 31 | local theRank = check[`i'] 32 | local theLabels = `"`theLabels' `theRank' "`theState'" "' 33 | } 34 | 35 | graph dot any regsim_1 regsim_2 regsim_3 /// 36 | , over(state, sort(4) descending axis(noline) label(labsize(small))) /// 37 | marker(1, m(T) msize(*3) mlc(white) mlw(vthin) mla(center)) /// 38 | marker(2, m(O) msize(*3) mlc(white) mlw(vthin) mla(center)) /// 39 | marker(3, m(S) msize(*3) mlc(white) mlw(vthin) mla(center)) /// 40 | marker(4, m(D) msize(*3) mlc(white) mlw(vthin) mla(center)) /// 41 | linetype(line) line(lw(thin) lc(gs14)) /// 42 | legend(on span c(1) size(small) order( /// 43 | 1 "Villages with any providers" /// 44 | 2 "Villages with MBBS providers" /// 45 | 3 "Villages with providers better than state average MBBS" /// 46 | 4 "Villages with providers better than national average MBBS")) /// 47 | ylab(${pct}) ytit("Proportion of villages {&rarr}") yscale(r(0) noline) /// 48 | legend(region(lc(none) fc(none))) noextendline ysize(6) /// 49 | ytit(,placement(left) justification(left)) 50 | 51 | * Have a lovely day! 52 | -------------------------------------------------------------------------------- /Library/do/eventstudy-prepost.do: -------------------------------------------------------------------------------- 1 | /* 2 | Figure: Simple event study graph 3 | 4 | Data Source: 5 | --------------------- 6 | This is a mock data set. 7 | */ 8 | 9 | use "https://github.com/worldbank/stata-visual-library/raw/master/Library/data/eventstudy-prepost.dta", clear 10 | 11 | /// Get time point of reference 12 | sum t 13 | local tmax = r(max) 14 | local tmin = r(min) 15 | 16 | sum t if post == 0 17 | local tevent = r(max) // This is the base period 18 | local tpostmin = `tevent' 19 | 20 | /// Calculate post-event average 21 | reg y post 22 | 23 | mat results = r(table) 24 | 25 | local postcons = results[1,1] 26 | local postll = results[5,1] 27 | local postul = results[6,1] 28 | 29 | /// Calculate effect for each ride 30 | reg y ib`tevent'.t // t = 0 is the time of the event 31 | 32 | /// Load the results as the data set so they're easier to handle 33 | mat pointest = r(table) 34 | mat pointest = pointest' 35 | 36 | 37 | /// Clear, and Load data ready for plotting 38 | clear 39 | svmat pointest, names(col) 40 | local lastobs = _N 41 | gen time = _n 42 | drop in `lastobs' // this is the constant 43 | 44 | 45 | twoway /// 46 | (rspike ul ll time, msize(tiny) color(gs10)) /// 47 | (scatter b time, msize(tiny) color(gs8)) /// 48 | (scatteri 0 0 0 `tevent', recast(connected) msymbol(none) lcolor(cranberry)) /// 49 | (scatteri `postcons' `tevent' `postcons' `tmax', recast(connected) msymbol(none) lcolor(navy)) /// 50 | (scatteri `postul' `tevent' `postul' `tmax', recast(connected) lpattern(dash) msymbol(none) lcolor(navy)) /// 51 | (scatteri `postll' `tevent' `postll' `tmax', recast(connected) lpattern(dash) msymbol(none) lcolor(navy)) /// 52 | , /// 53 | graphregion(color(white)) /// 54 | legend(off) /// 55 | xlabel(none) /// 56 | xtitle(Time) /// 57 | ytitle(Outcome variable) /// 58 | title("Event Study Graph", justification(left) color(black) span pos(17)) 59 | 60 | * Have a lovely day! 61 | 62 | -------------------------------------------------------------------------------- /Library/do/line-fit-text.do: -------------------------------------------------------------------------------- 1 | /* 2 | Figure: Line plots witthed line with confidence interval 3 | 4 | Data Source: 5 | --------------------- 6 | Mock data and code based on 7 | Christian,Paul J.; Kondylis,Florence; Mueller,Valerie Martina; Zwager,Astrid Maria Theresia; Siegfried,Tobias.2018. 8 | Water when it counts : reducing scarcity through irrigation monitoring in Central Mozambique (English). 9 | Policy Research working paper;no. WPS 8345;Impact Evaluation series Washington, D.C. : World Bank Group. 10 | http://documents.worldbank.org/curated/en/206391519136157728/Water-when-it-counts-reducing-scarcity-through-irrigation-monitoring-in-Central-Mozambique 11 | */ 12 | 13 | use "https://github.com/worldbank/stata-visual-library/raw/master/Library/data/line-fit-text.dta", clear 14 | 15 | /// Treament effect 16 | reg y_var x_var post x_var_post control 17 | 18 | /// Saving coefficient 19 | local beta_pre = round(_b[x_var],0.001) 20 | local beta_post = round(_b[x_var] + _b[x_var_post],0.001) 21 | 22 | /// Saving F Test test _b[x_var_post] = 1 23 | local f_pre = round(r(p),0.001) 24 | if `f_pre' == 0 local f_pre = "0.000" 25 | 26 | test _b[x_var_post] + _b[x_var_post] = 1 27 | local f_post = round(r(p),0.001) 28 | 29 | 30 | twoway (lfitci y_hat x_var if post == 1, color("222 235 247") lwidth(.05)) /// 31 | (lfitci y_hat x_var if post == 0, color(gs15)) /// 32 | (lfit x_var x_var if post == 1, color(red) lwidth(.5) lpattern(dash)) /// 33 | (lfit y_hat x_var if post == 0, color(gs8) lwidth(.5)) /// 34 | (lfit y_hat x_var if post == 1, color(edkblue) lwidth(.5)), /// 35 | text(5 9 "Pre-treatment" "Regression coefficent: 0`beta_pre'" "P-value of coefficent = 1: `f_pre'" /// 36 | 12 9 "Post-treatment" "Regression coefficent: 0`beta_post'" "P-value of coefficent = 1: 0`f_post'", /// 37 | orient(horizontal) size(vsmall) justification(center) fcolor(white) box margin(small)) /// 38 | xtitle("Independent variable value") /// 39 | ytitle("Predicted value of dependent variable") /// 40 | legend(order (6 "Pre-treatment" 7 "Post-treatment" 3 "Pre-treatment 95%CI" 1 "Pre-treatment 95%CI")) /// 41 | graphregion(color(white)) bgcolor(white) /// 42 | title("Line plots witthed line with confidence interval", justification(left) color(black) span pos(11)) 43 | 44 | * Have a lovely day! 45 | -------------------------------------------------------------------------------- /Library/do/line-plottig.do: -------------------------------------------------------------------------------- 1 | /* 2 | Figure: Line graph with plottig scheme 3 | 4 | Data Source: 5 | ------------------ 6 | sp500 from default Stata directory 7 | 8 | Install Scheme (if needed) 9 | ----------------------------- 10 | We need one scheme to run this file: blindschemes 11 | Please remove "*" from below lines if you have not installed them and would like to install. 12 | */ 13 | 14 | * ssc install blindschemes, replace 15 | 16 | /// Select graph scheme (similar to R's ggplot2) 17 | set scheme plottig 18 | 19 | /// Load built-in data 20 | sysuse sp500, clear 21 | 22 | /// Create graph: show time series for 4 variables 23 | twoway (line high date) /// 24 | (line low date) /// 25 | (line close date) /// 26 | (line open date) , /// 27 | title("Line graph with plottig scheme",justification(left) color(black) span pos(11)) 28 | 29 | * Have a lovely day! 30 | -------------------------------------------------------------------------------- /Library/do/line-uncluttered.do: -------------------------------------------------------------------------------- 1 | /* 2 | Figure: Line graph with uncluttered scheme 3 | 4 | Data Source: 5 | --------------------- 6 | Stata built-in dataset: uslifeexp 7 | 8 | Install Scheme (if needed): 9 | --------------------- 10 | Change scheme: scheme needs to be manually installed. Instruction on how 11 | to this can be found in https://gray.kimbrough.info/uncluttered-stata-graphs/ 12 | Step 1: go to https://gray.kimbrough.info/uncluttered-stata-graphs/ 13 | Step 2: click on "scheme" or go https://github.com/graykimbrough/uncluttered-stata-graphs/tree/master/schemes 14 | Step 3: Download two .scheme file in that github directionary 15 | Step 4: Place the .scheme file(s) in your Stata PERSONAL directory (if you dont know where, run "sysdir" in STATA Command) 16 | Step 5: run "set scheme uncluttered, permanent" in STATA Command 17 | 18 | 19 | */ 20 | 21 | sysuse uslifeexp, clear 22 | set scheme uncluttered 23 | 24 | line le le_male le_female year /// 25 | , /// 26 | ytitle(Life expectancy (years)) /// 27 | legend(on /// Scheme supresses the legend by default 28 | order(1 "Overall" /// Set label to show up in legend 29 | 2 "Male" /// 30 | 3 "Female") /// 31 | cols(3) /// Show all legends in one line (3 columns) 32 | pos(12)) /// Show legend on top of graph 33 | title("Line graph with uncluttered scheme", justification(left) color(black) span pos(11)) 34 | 35 | * Have a lovely Day! 36 | -------------------------------------------------------------------------------- /Library/do/map-world.do: -------------------------------------------------------------------------------- 1 | /* 2 | Figure: Map 3 | 4 | Data Source: 5 | -------------------------- 6 | Below codes are replicated from 7 | 8 | Joao Pedro Azevedo, 2011. "WBOPENDATA: Stata module to access World Bank databases," 9 | Statistical Software Components S457234, Boston College Department of Economics, revised 09 Jul 2020. 10 | 11 | The author Joao Pedro Azevedo also made available more examples using wbopendata available at https://github.com/jpazvd/wbopendata 12 | 13 | Install Packages (if needed): 14 | ---------------------------- 15 | We need one package to run this file: wbopendata 16 | Please remove "*" from below lines if you have not installed them and would like to install. 17 | 18 | */ 19 | * ssc install wbopendata, replace 20 | 21 | /// create a tempfile to store data mined from WDI using wbopendata 22 | qui tempfile WDIdata 23 | wbopendata, language(en - English) indicator(it.cel.sets.p2) long clear latest 24 | local labelvar "`r(varlabel1)'" 25 | sort countrycode 26 | save `WDIdata', replace 27 | 28 | /// create another tempfile from the world-c.dta which include X and Y coordinate of the country 29 | qui tempfile worldc 30 | qui sysuse world-c.dta, clear 31 | save `worldc'.dta, replace 32 | 33 | /// merge with world-d.dta which include areas of the country 34 | qui sysuse world-d.dta, clear 35 | qui merge countrycode using `WDIdata' 36 | qui sum year 37 | local avg = string(`r(mean)',"%16.1f") 38 | 39 | ///map out 40 | spmap it_cel_sets_p2 using `worldc' /// 41 | , id(_ID) clnumber(20) fcolor(Reds2) ocolor(none ..) /// 42 | title("`labelvar'", size(*1.2)) legstyle(3) legend(ring(1) position(3)) /// 43 | note("Source: World Development Indicator") 44 | 45 | * Have a lovely day! 46 | -------------------------------------------------------------------------------- /Library/do/reg-chartable.do: -------------------------------------------------------------------------------- 1 | /* 2 | Figure : Impact of provider qualifications on main standardized patient outcomes 3 | 4 | Data Source: 5 | -------------------------- 6 | 7 | Das, Jishnu, Liana Woskie, Ruma Rajbhandari, Kamran Abbasi, and Ashish Jha. 8 | “Rethinking assumptions about delivery of healthcare: implications for universal health coverage.” Bmj 361 (2018). 9 | 10 | Install Library (if needed): 11 | --------------------------- 12 | We need three packages to run this file: firthlogit, st0085_2 (estadd) , dm0037 (xml_tab) 13 | Please remove "*" from below lines if you have not installed them and would like to install. 14 | */ 15 | * ssc inst firthlogit 16 | * net from http://www.stata-journal.com/software/sj14-2 17 | * net install st0085_2 18 | * net from http://www.stata-journal.com/software/sj8-3 19 | * net install dm0037 20 | 21 | /// Load adofiles 22 | * These files are created by the authors for the purposes of this study and are not publicly available for general use. 23 | * These files are not guaranteed to produce appropriate statistics other than those contained in this replication file. 24 | 25 | qui do "https://github.com/worldbank/stata-visual-library/raw/master/Library/ado/chartablesheet.ado" 26 | 27 | use "https://github.com/worldbank/stata-visual-library/raw/master/Library/data/reg-chartable.dta", clear 28 | 29 | /// Sample Restriction Logic 30 | global cxr "& sp_case <3" 31 | global sputum "& sp_case <3" 32 | global sp_drugs_tb "& sp_case >2" 33 | 34 | /// Output 35 | chartable correct cxr sputum s5_referral sp_drugs_tb sp_drugs_antibio sp_drugs_quin /// 36 | using "results.xlsx" /// 37 | , /// 38 | c(xi: firthlogit) /// 39 | rhs(q_mbbs pro_age pro_male patients_waiting_in i.sp_id) or p globalif /// 40 | title("Impact of provider qualifications on main standardized patient outcomes", justification(left) color(black) span pos(11)) 41 | 42 | * Have a lovely day! 43 | -------------------------------------------------------------------------------- /Library/do/reg-het.do: -------------------------------------------------------------------------------- 1 | /* 2 | Figure: Marginal effects by heterogeneity groups 3 | 4 | Data Source: 5 | -------------------------- 6 | Use built-in data: auto 7 | */ 8 | sysuse auto, clear 9 | 10 | /// prepare option 11 | local label1 Foreign 12 | local label0 Domestic 13 | 14 | /// Supress y axis labels on graph to the right so it's only shown once on 15 | /// combined graph 16 | local yopts1 ylab(, labcolor(white)) /// 17 | ytitle("") /// 18 | yscale(noline) 19 | 20 | gr drop _all 21 | 22 | * install coefplot 23 | ssc install coefplot, replace 24 | 25 | /// create individual graph 26 | /// Loop over heterogeneity variables 27 | forvalues foreign = 0/1 { 28 | reg price mpg headroom if foreign == `foreign' /// Run regression to get margin effect 29 | 30 | /// Plot marginal effect by group 31 | coefplot /// 32 | , /// 33 | drop(_cons) /// don't show constant 34 | vertical /// 35 | yline(0, lpattern(dash)) /// for significance 36 | ciopt(color(gs10 gs10) /// 37 | recast(rcap)) /// 38 | levels(90 95) /// show 90% and 95% CIs 39 | ylab(, noticks glcolor(gs15)) /// 40 | xlab(, noticks labsize(small)) /// 41 | xtitle("") /// 42 | ytitle("Marginal effect on price") /// 43 | title(`label`foreign'', box bexpand bcolor(gs15)) /// add title in box 44 | color(black) /// 45 | name(f`foreign') /// 46 | graphregion(color(white)) /// 47 | `yopts`foreign'' 48 | } 49 | 50 | /// Combine graph 51 | gr combine f0 f1, /// 52 | ycommon /// 53 | graphregion(color(white)) /// 54 | title("Marginal effects by heterogeneity groups", justification(left) color(black) span pos(11)) 55 | 56 | 57 | * Have a lovely day! 58 | -------------------------------------------------------------------------------- /Library/do/reg-models.do: -------------------------------------------------------------------------------- 1 | /* 2 | Figure: Comparison of marginal effects from linear and logistic specifications 3 | 4 | Data Source: 5 | -------------------------- 6 | 7 | Satyanarayana S, Kwan A, Daniels B, Subbaraman R, McDowell A, Bergkvist S, Das RK, Das V, Das J, Pai M. 8 | Use of standardised patients to assess antibiotic dispensing for tuberculosis by pharmacies in urban India: A cross-sectional study. 9 | The Lancet Infectious Diseases. 2016 Nov 30;16(11):1261-8. 10 | 11 | Workflow explanation: 12 | The code takes the results from a linear regression and a logit regression 13 | and saves the coefficients, and the upper and lower bounds of the confidence 14 | intervals into a matrix (results). The twoway command will take the estimates 15 | and plot a comparison of marginal effects from the two specifications. 16 | */ 17 | 18 | global graph_opts title(, justification(left) color(black) span pos(11)) graphregion(color(white)) ylab(,angle(0) nogrid) xtit(,placement(left) justification(left)) yscale(noline) xscale(noline) legend(region(lc(none) fc(none))) 19 | 20 | use "https://github.com/worldbank/stata-visual-library/raw/master/Library/data/reg-models.dta" , clear 21 | 22 | cap mat drop theResults 23 | local theLabels "" 24 | local x = 15.5 25 | 26 | qui foreach var of varlist ??_correct refer med_any med_class_any_6 med_class_any_16 { 27 | 28 | local theLabel : var label `var' 29 | local theLabels `"`theLabels' `x' "`theLabel'""' 30 | local x = `x' - 2 31 | 32 | reg `var' facility_private i.case_code 33 | 34 | mat a = r(table) 35 | 36 | local b = a[1,1] 37 | local ll = a[5,1] 38 | local ul = a[6,1] 39 | mat a = [`b',`ll',`ul',1] 40 | mat rownames a = "`var'" 41 | 42 | logit `var' facility_private i.case_code 43 | margins , dydx(facility_private) 44 | 45 | mat b = r(table) 46 | 47 | local b = b[1,1] 48 | local ll = b[5,1] 49 | local ul = b[6,1] 50 | mat b = [`b',`ll',`ul',2] 51 | mat rownames b = "`var'" 52 | 53 | mat theResults = nullmat(theResults) \ a \ b 54 | } 55 | 56 | mat colnames theResults = "b" "ll" "ul" "type" 57 | matlist theResults 58 | 59 | clear 60 | svmat theResults , names(col) 61 | 62 | gen n = _n 63 | replace n = 17-n 64 | tw /// 65 | (rcap ll ul n if type == 1 , hor lc(navy)) /// 66 | (scatter n b if type == 1 , mc(black)) /// 67 | (rcap ll ul n if type == 2 , hor lc(maroon)) /// 68 | (scatter n b if type == 2 , mc(black)) /// 69 | , /// 70 | ${graph_opts} /// 71 | ylab(`theLabels') /// 72 | ytit(" ") /// 73 | xlab(-1 "-100p.p." -.5 `""-50p.p." "{&larr} Favors Public""' 0 "No Effect" .5 `""+50p.p." "Favors Private {&rarr}""' 1 "+100p.p.") /// 74 | xline(0 , lc(gs12) lp(dash)) /// 75 | legend(order(2 "Marginal Effect" 1 "Linear Model" 3 "Logistic Model") r(1)) /// 76 | title("Comparison of marginal effects", justification(left) color(black) span pos(11)) 77 | 78 | * Have a lovely day! 79 | -------------------------------------------------------------------------------- /Library/do/reg-predicted.do: -------------------------------------------------------------------------------- 1 | /* 2 | Figure: Adjusted prediction of car price with 95% confidence interval 3 | 4 | Data Source: 5 | -------------------------- 6 | Use built-in data: auto 7 | */ 8 | 9 | sysuse auto, clear 10 | 11 | reg price ibn.foreign 12 | 13 | /// Test if take up if the same across positive opportunity cost levels, then 14 | /// create and format local to add to the graph as text 15 | test 1.foreign == 0.foreign 16 | local pval : di %5.3f `r(p)' 17 | local pval = trim("`pval'") 18 | 19 | /// Calculate the predicted value for each category 20 | margins foreign 21 | 22 | * Create plot 23 | marginsplot, /// 24 | recast(bar) /// 25 | plotopts(barwidth(0.5) bargap(10)) /// 26 | ciopts(recast(rcap) color(gs10)) /// 27 | ylabel(0(2000)8000) /// 28 | title("Adjusted prediction of car price" "with 95% confidence interval", justification(center) color(black) span pos(17)) /// 29 | xlabel(, noticks) /// 30 | xtitle(Model origin) /// 31 | graphregion(color(white)) /// 32 | note(Note: P-value of F-test for coefficient equality across categories is `pval'.) 33 | 34 | * Have a lovely day! 35 | -------------------------------------------------------------------------------- /Library/do/regression-fit.do: -------------------------------------------------------------------------------- 1 | /* 2 | Figure: Regression Fit 3 | 4 | Data Source: 5 | --------------------- 6 | Jishnu Das, Benjamin Daniels, Monisha Ashok, Eun-Young Shim, and Karthik Muralidharan 7 | Two Indias: The structure of primary health care markets in rural Indian villages with implications for policy. 8 | doi: https://doi.org/10.1016/j.socscimed.2020.112799 9 | repo: https://github.com/bbdaniels/ssm-rhcp-2020 10 | 11 | */ 12 | 13 | use "https://github.com/worldbank/stata-visual-library/blob/bbd-graphs/Library/data/regression-fit.dta?raw=true" , clear 14 | 15 | keep uvillid private state_code type_1 type_2 type_3 type_4 smses weight_psu u5mr 16 | 17 | reshape wide type_? /// 18 | , i(uvillid) j(private) // Reduce to village level 19 | drop type_4? // Exclude unknown providers 20 | 21 | // Total number of providers per village 22 | egen nprov = rowtotal(type*) 23 | 24 | // Collapse to state level 25 | collapse /// 26 | (firstnm) smses u5mr /// 27 | (mean) type* nprov /// average numbers of providers per village 28 | [pweight = weight_psu] , by(state_code) 29 | 30 | // Calculate share of non-mbbs private providers 31 | gen nonmbbs = (type_31 + type_21) / nprov 32 | 33 | // Normalize state-mean SES 34 | egen norm = std(smses) 35 | 36 | // Calculate regression coefficients 37 | reg nonmbbs norm 38 | mat a = r(table) 39 | local b1 = a[1,1] 40 | local p1 = a[4,1] 41 | local r1 = e(r2) 42 | reg nonmbbs norm if nonmbbs > 0.4 // Exclude Kerala 43 | mat a = r(table) 44 | local b2 = a[1,1] 45 | local p2 = a[4,1] 46 | local r2 = e(r2) 47 | 48 | foreach param in b1 p1 b2 p2 r1 r2 { 49 | local `param' : di %3.2f ``param'' 50 | } 51 | 52 | // Graph 53 | tw /// 54 | (lfitci nonmbbs norm , lc(black) lp(dash) acolor(gs14) alp(none) ) /// 55 | (lpoly nonmbbs norm , lw(thick) lc(maroon) ) /// 56 | (scatter nonmbbs norm , m(.) mc(black) mlab(state_code) mlabangle(20) mlabc(black) mlabpos(9) mlabsize(vsmall)) /// 57 | (scatteri 0.10 -2 "Regression Coefficient: `b1' (p=`p1', R{superscript:2}=`r1')" , m(none) mlabc(black)) /// 58 | (scatteri 0.05 -2 "Regression Ex. Kerala: `b2' (p=`p2', R{superscript:2}=`r2')" , m(none) mlabc(black)) /// 59 | , title("") note("") legend(off) /// 60 | ylab($pct) ytit("Share of Private Non-MBBS Providers" , placement(left) justification(left)) /// 61 | xlab(-2 "-2 SD" -1 "-1 SD" 0 `""Average" "{&larr} State SES {&rarr}""' 1 "+1 SD" 2 "+2 SD") xtit("") 62 | 63 | * Have a lovely day! 64 | -------------------------------------------------------------------------------- /Library/do/scatter-fl-ci.do: -------------------------------------------------------------------------------- 1 | /* 2 | Figure : Make a scatter plot with confidence interval 3 | 4 | Data Source: 5 | -------------------------- 6 | Data replicated from: 7 | 8 | World Development Indicator 9 | */ 10 | 11 | use "https://github.com/worldbank/stata-visual-library/raw/develop/Library/data/scatter-fl-ci.dta", clear 12 | 13 | twoway (lfitci gdp_per_cap_growth morality_rate) /// 14 | (scatter gdp_per_cap_growth morality_rate if continent == "Europe & Central Asia", mcolor(cranberry) m(O) ) /// 15 | (scatter gdp_per_cap_growth morality_rate if continent == "South Asia", mcolor(dkgreen) m(D) ) /// 16 | (scatter gdp_per_cap_growth morality_rate if continent == "Middle East & North Africa", mcolor(ebblue ) m(T) ) /// 17 | (scatter gdp_per_cap_growth morality_rate if continent == "East Asia & Pacific", mcolor(dkorange) m(O)) /// 18 | (scatter gdp_per_cap_growth morality_rate if continent == "Sub-Saharan Africa", mcolor(navy) m(D) ) /// 19 | (scatter gdp_per_cap_growth morality_rate if continent == "Latin America & Caribbean", mcolor(red) m(T)) /// 20 | (scatter gdp_per_cap_growth morality_rate if continent == "North Amercia", mcolor(yellow) m(D)) /// 21 | , /// 22 | xlabel(0(20)120) /// 23 | xtitle("Morality Rate under 5 (Per 1,000 lives) ", axis(1)) /// 24 | ylabel(-10(5)25) /// 25 | ytitle("Annual GDP per Capita Growth Rate (%)" ) /// 26 | legend(order( 3 4 5 6 7 8 9) label(3 "East Asia & Pacific") label(4 "Europe & Central Asia") /// 27 | label(5 "Latin America & Caribbean") label(6 "Middle East & North Africa") label(7 "North America") /// 28 | label(8 "South America") label(9 "Sub-Saharan Africa") /// 29 | ring(0) position(1)) /// 30 | title("Morality Rate under 5 and GDP per Capita Growth " "Correlation") /// 31 | note("Source: World Development Indicatior (2019)") /// 32 | graphregion(color(white)) bgcolor(white) 33 | 34 | * Have a lovely day! 35 | -------------------------------------------------------------------------------- /Library/do/scatter-fl.do: -------------------------------------------------------------------------------- 1 | /* 2 | Figure: scatter plot with fitted line 3 | 4 | Data Source: 5 | -------------------------- 6 | Use built-in data: auto 7 | */ 8 | 9 | sysuse auto, clear 10 | 11 | /// graph options 12 | local col_domestic midblue 13 | local col_foreign red 14 | local transparency %30 15 | local point_width 0 16 | local point_size small 17 | 18 | twoway /// 19 | (scatter price mpg if foreign == 0, mfcolor(`col_domestic'`transparency') msize(`point_size') mlwidth(`point_width')) /// 20 | (lfit price mpg if foreign == 0, color(`col_domestic')) /// 21 | (scatter price mpg if foreign == 1, mfcolor(`col_foreign'`transparency') msize(`point_size') mlwidth(`point_width')) /// 22 | (lfit price mpg if foreign == 1, color(`col_foreign')) /// 23 | , /// 24 | graphregion(color(white)) /// 25 | legend(order(2 "Domestic" 4 "Foreign")) /// 26 | title("Scatter plot with fitted line", justification(center) color(black) span pos(17)) 27 | -------------------------------------------------------------------------------- /Library/do/scatter-poly-ci.do: -------------------------------------------------------------------------------- 1 | /* 2 | Figure: Scatter plot with polynomial smoothing and confidence interval 3 | 4 | Data Source: 5 | -------------------------- 6 | Data replicated from: 7 | 8 | Christian, Paul, and Brian Dillon. 2018. “Growing and Learning When Consumption Is Seasonal: 9 | Long-Term Evidence From Tanzania.” Demography 55 (3): 1091–1118. doi:10.1007/s13524-018-0669-4. 10 | 11 | with some noises being added 12 | 13 | Install Packages (if needed) 14 | ---------------------------- 15 | We need one package to run this file: grc1leg 16 | Please remove "*" from below lines if you have not installed it and would like to install. 17 | */ 18 | 19 | * net from http://www.stata.com 20 | * net cd users 21 | * net cd vwiggins 22 | * net install grc1leg 23 | 24 | /// Load data 25 | use "https://github.com/worldbank/stata-visual-library/raw/master/Library/data/scatter-poly-ci.dta", clear 26 | 27 | /// Create First Graph 28 | sum cons_pae_m_sine, det 29 | 30 | twoway (scatter cons_pae_sd_sine cons_pae_m_sine if cons_pae_m_sine < `r(p99)') /// 31 | (lpolyci cons_pae_sd_sine cons_pae_m_sine if cons_pae_m_sine < `r(p99)') /// 32 | , /// 33 | legend(off) /// 34 | xtitle(" " "`=ustrunescape("\u006D\u0302")'", size(large)) /// m-hat 35 | ytitle("`=ustrunescape("\u0073\u0302")'" " ", size(large)) /// s-hat 36 | xlabel(50 "50" 100 "100" 150 "150" 200 "200") /// 37 | graphregion(color(white)) bgcolor(white) /// 38 | name(s_by_mhat) 39 | 40 | /// Create Second Graph 41 | sum cons_pae_m_sine, det 42 | twoway (scatter cv cons_pae_m_sine if cons_pae_m_sine<`r(p99)' & cons_pae_m_sine>`r(p1)') /// 43 | (lpolyci cv cons_pae_m_sine if cons_pae_m_sine<`r(p99)' & cons_pae_m_sine>`r(p1)') /// 44 | , /// 45 | ytitle("`=ustrunescape("\u0073\u0302/\u006D\u0302")'" " ", size(large)) /// s-hat/m-hat 46 | xtitle(" " "`=ustrunescape("\u006D\u0302")'", size(large)) /// m-hat 47 | legend(order(2 3) label(3 "Local Poly.") label(2 "95% CI")) /// 48 | graphregion(color(white)) bgcolor(white) /// 49 | name(cv_by_mhat) 50 | 51 | /// Combine graphs 52 | grc1leg s_by_mhat cv_by_mhat /// 53 | , /// 54 | row(1) legendfrom(cv_by_mhat) /// 55 | imargin(0 0 0 0) graphregion(margin(t=0 b=0)) /// 56 | position(6) fysize(75) fxsize(150) /// 57 | graphregion(color(white)) plotregion(color(white)) /// 58 | title("Scatter plot with polynomial smoothing" "and confidence interval", justification(center) color(black) span pos(17)) 59 | 60 | * Have a lovely day! 61 | -------------------------------------------------------------------------------- /Library/do/scatter-strata.do: -------------------------------------------------------------------------------- 1 | /* 2 | Figure: Regression Coefficient plot 3 | 4 | Data Source: 5 | -------------------------- 6 | Data replicated from: 7 | 8 | Das, Jishnu, Liana Woskie, Ruma Rajbhandari, Kamran Abbasi, and Ashish Jha. 9 | “Rethinking assumptions about delivery of healthcare: implications for universal health coverage.” Bmj 361 (2018). 10 | 11 | 12 | Install Packages (if needed) 13 | ---------------------------- 14 | We need three packages to run this file: firthlogit, st0085_2 (estadd) , dm0037 (xml_tab) 15 | Please remove "*" from below lines if you have not installed it and would like to install. 16 | */ 17 | 18 | * ssc inst firthlogit 19 | * net from http://www.stata-journal.com/software/sj14-2 20 | * net install st0085_2 21 | * net from http://www.stata-journal.com/software/sj8-3 22 | * net install dm0037 23 | 24 | run "https://raw.githubusercontent.com/worldbank/stata-visual-library/master/Library/ado/freeshape.ado" 25 | run "https://raw.githubusercontent.com/worldbank/stata-visual-library/master/Library/ado/labelcollapse.ado" 26 | 27 | /// Load data 28 | use "https://github.com/worldbank/stata-visual-library/raw/master/Library/data/scatter-strata.dta", clear 29 | 30 | /// Collapse and reshape data 31 | labelcollapse essential correct cxr sputum dstgx s5_referral sp_drugs_tb sp_drugs_antibio sp_drugs_quin, by(sp_case) 32 | freeshape essential correct cxr sputum dstgx s5_referral sp_drugs_tb sp_drugs_antibio sp_drugs_quin, i(sp_case) j(var) 33 | 34 | /// Assign ordered number 35 | local x = 1 36 | gen order = 0 37 | 38 | qui foreach name in essential correct cxr sputum dstgx s5_referral sp_drugs_tb sp_drugs_antibio sp_drugs_quin { 39 | replace order = `x' if var_name == "`name'" 40 | local ++x 41 | } 42 | 43 | /// Create graph 44 | graph dot var_value /// 45 | , /// 46 | asy over(sp_case) over(var_label, sort(order)) /// 47 | linegap(20) /// 48 | graphregion(color(white)) /// 49 | xsize(7) /// 50 | legend(region(lc(none) fc(none))) /// 51 | yscale(noline) ytit("") ylab(0 "0%" .25 "25%" .5 "50%" .75 "75%" 1 "100%") /// 52 | linetype(line) lines( lp(.) lc(gs11)) /// 53 | legend(pos(5) ring(0) c(1) region(lc(white) fc(white))) /// 54 | marker(1, m(O) mlcolor(black)) /// 55 | marker(2, m(O) mlcolor(black)) /// 56 | marker(3, m(O) mlcolor(black)) /// 57 | marker(4, m(O) mlcolor(black)) /// 58 | title("Regression Coefficient plot", justification(center) color(black) span pos(17)) 59 | 60 | * Have a good day! 61 | -------------------------------------------------------------------------------- /Library/do/scatter-transparent.do: -------------------------------------------------------------------------------- 1 | /* 2 | Figure: Scatter plot with transparent points 3 | 4 | Data Source: 5 | -------------------------- 6 | Use built-in data: auto 7 | */ 8 | 9 | sysuse auto, clear 10 | 11 | scatter /// 12 | price mpg /// 13 | , /// 14 | mcolor(midblue%50) /// the value after % sets the transparency 15 | mlwidth(0) /// set width of border to 0 16 | graphregion(color(white)) /// 17 | title("Scatter plot with transparent points", justification(center) color(black) span pos(17)) 18 | 19 | * Have a lovely day! 20 | -------------------------------------------------------------------------------- /Library/dot-summary.html: -------------------------------------------------------------------------------- 1 | /* 2 | Figure: Binned scatter plot 3 | 4 | Data Source: 5 | --------------------- 6 | Jishnu Das, Benjamin Daniels, Monisha Ashok, Eun-Young Shim, and Karthik Muralidharan 7 | Two Indias: The structure of primary health care markets in rural Indian villages with implications for policy. 8 | doi: https://doi.org/10.1016/j.socscimed.2020.112799 9 | repo: https://github.com/bbdaniels/ssm-rhcp-2020 10 | */ 11 | 12 | use "https://github.com/worldbank/stata-visual-library/blob/bbd-graphs/Library/data/dot-summary.dta?raw=true" , clear 13 | 14 | egen total = rsum(type_?) 15 | gen any = (total>0) 16 | 17 | collapse (max) any regsim_? (mean) weight_psu , by(state_code villid) fast 18 | collapse (mean) any (mean) regsim_? , by(state_code) 19 | 20 | forvalues i = 1/3 { 21 | replace regsim_`i' = regsim_`i'*any 22 | } 23 | 24 | egen check = rank(regsim_3) , unique 25 | sort check 26 | decode state_code , gen(state) 27 | 28 | qui count 29 | forvalues i = 1/`r(N)' { 30 | local theState = state[`i'] 31 | local theRank = check[`i'] 32 | local theLabels = `"`theLabels' `theRank' "`theState'" "' 33 | } 34 | 35 | graph dot any regsim_1 regsim_2 regsim_3 /// 36 | , over(state, sort(4) descending axis(noline) label(labsize(small))) /// 37 | marker(1, m(T) msize(*3) mlc(white) mlw(vthin) mla(center)) /// 38 | marker(2, m(O) msize(*3) mlc(white) mlw(vthin) mla(center)) /// 39 | marker(3, m(S) msize(*3) mlc(white) mlw(vthin) mla(center)) /// 40 | marker(4, m(D) msize(*3) mlc(white) mlw(vthin) mla(center)) /// 41 | linetype(line) line(lw(thin) lc(gs14)) /// 42 | legend(on span c(1) size(small) order( /// 43 | 1 "Villages with any providers" /// 44 | 2 "Villages with MBBS providers" /// 45 | 3 "Villages with providers better than state average MBBS" /// 46 | 4 "Villages with providers better than national average MBBS")) /// 47 | ylab(${pct}) ytit("Proportion of villages {&rarr}") yscale(r(0) noline) /// 48 | legend(region(lc(none) fc(none))) noextendline ysize(6) /// 49 | ytit(,placement(left) justification(left)) 50 | 51 | * Have a lovely day! 52 | -------------------------------------------------------------------------------- /Library/eventstudy-prepost.html: -------------------------------------------------------------------------------- 1 | /* 2 | Figure: Simple event study graph 3 | 4 | Data Source: 5 | --------------------- 6 | This is a mock data set. 7 | */ 8 | 9 | use "https://github.com/worldbank/stata-visual-library/raw/master/Library/data/eventstudy-prepost.dta", clear 10 | 11 | /// Get time point of reference 12 | sum t 13 | local tmax = r(max) 14 | local tmin = r(min) 15 | 16 | sum t if post == 0 17 | local tevent = r(max) // This is the base period 18 | local tpostmin = `tevent' 19 | 20 | /// Calculate post-event average 21 | reg y post 22 | 23 | mat results = r(table) 24 | 25 | local postcons = results[1,1] 26 | local postll = results[5,1] 27 | local postul = results[6,1] 28 | 29 | /// Calculate effect for each ride 30 | reg y ib`tevent'.t // t = 0 is the time of the event 31 | 32 | /// Load the results as the data set so they're easier to handle 33 | mat pointest = r(table) 34 | mat pointest = pointest' 35 | 36 | 37 | /// Clear, and Load data ready for plotting 38 | clear 39 | svmat pointest, names(col) 40 | local lastobs = _N 41 | gen time = _n 42 | drop in `lastobs' // this is the constant 43 | 44 | 45 | twoway /// 46 | (rspike ul ll time, msize(tiny) color(gs10)) /// 47 | (scatter b time, msize(tiny) color(gs8)) /// 48 | (scatteri 0 0 0 `tevent', recast(connected) msymbol(none) lcolor(cranberry)) /// 49 | (scatteri `postcons' `tevent' `postcons' `tmax', recast(connected) msymbol(none) lcolor(navy)) /// 50 | (scatteri `postul' `tevent' `postul' `tmax', recast(connected) lpattern(dash) msymbol(none) lcolor(navy)) /// 51 | (scatteri `postll' `tevent' `postll' `tmax', recast(connected) lpattern(dash) msymbol(none) lcolor(navy)) /// 52 | , /// 53 | graphregion(color(white)) /// 54 | legend(off) /// 55 | xlabel(none) /// 56 | xtitle(Time) /// 57 | ytitle(Outcome variable) /// 58 | title("Event Study Graph", justification(left) color(black) span pos(17)) 59 | 60 | * Have a lovely day! 61 | 62 | -------------------------------------------------------------------------------- /Library/line-fit-text.html: -------------------------------------------------------------------------------- 1 | /* 2 | Figure: Line plots witthed line with confidence interval 3 | 4 | Data Source: 5 | --------------------- 6 | Mock data and code based on 7 | Christian,Paul J.; Kondylis,Florence; Mueller,Valerie Martina; Zwager,Astrid Maria Theresia; Siegfried,Tobias.2018. 8 | Water when it counts : reducing scarcity through irrigation monitoring in Central Mozambique (English). 9 | Policy Research working paper;no. WPS 8345;Impact Evaluation series Washington, D.C. : World Bank Group. 10 | http://documents.worldbank.org/curated/en/206391519136157728/Water-when-it-counts-reducing-scarcity-through-irrigation-monitoring-in-Central-Mozambique 11 | */ 12 | 13 | use "https://github.com/worldbank/stata-visual-library/raw/master/Library/data/line-fit-text.dta", clear 14 | 15 | /// Treament effect 16 | reg y_var x_var post x_var_post control 17 | 18 | /// Saving coefficient 19 | local beta_pre = round(_b[x_var],0.001) 20 | local beta_post = round(_b[x_var] + _b[x_var_post],0.001) 21 | 22 | /// Saving F Test test _b[x_var_post] = 1 23 | local f_pre = round(r(p),0.001) 24 | if `f_pre' == 0 local f_pre = "0.000" 25 | 26 | test _b[x_var_post] + _b[x_var_post] = 1 27 | local f_post = round(r(p),0.001) 28 | 29 | 30 | twoway (lfitci y_hat x_var if post == 1, color("222 235 247") lwidth(.05)) /// 31 | (lfitci y_hat x_var if post == 0, color(gs15)) /// 32 | (lfit x_var x_var if post == 1, color(red) lwidth(.5) lpattern(dash)) /// 33 | (lfit y_hat x_var if post == 0, color(gs8) lwidth(.5)) /// 34 | (lfit y_hat x_var if post == 1, color(edkblue) lwidth(.5)), /// 35 | text(5 9 "Pre-treatment" "Regression coefficent: 0`beta_pre'" "P-value of coefficent = 1: `f_pre'" /// 36 | 12 9 "Post-treatment" "Regression coefficent: 0`beta_post'" "P-value of coefficent = 1: 0`f_post'", /// 37 | orient(horizontal) size(vsmall) justification(center) fcolor(white) box margin(small)) /// 38 | xtitle("Independent variable value") /// 39 | ytitle("Predicted value of dependent variable") /// 40 | legend(order (6 "Pre-treatment" 7 "Post-treatment" 3 "Pre-treatment 95%CI" 1 "Pre-treatment 95%CI")) /// 41 | graphregion(color(white)) bgcolor(white) /// 42 | title("Line plots witthed line with confidence interval", justification(left) color(black) span pos(11)) 43 | 44 | * Have a lovely day! 45 | -------------------------------------------------------------------------------- /Library/line-plottig.html: -------------------------------------------------------------------------------- 1 | /* 2 | Figure: Line graph with plottig scheme 3 | 4 | Data Source: 5 | ------------------ 6 | sp500 from default Stata directory 7 | 8 | Install Scheme (if needed) 9 | ----------------------------- 10 | We need one scheme to run this file: blindschemes 11 | Please remove "*" from below lines if you have not installed them and would like to install. 12 | */ 13 | 14 | * ssc install blindschemes, replace 15 | 16 | /// Select graph scheme (similar to R's ggplot2) 17 | set scheme plottig 18 | 19 | /// Load built-in data 20 | sysuse sp500, clear 21 | 22 | /// Create graph: show time series for 4 variables 23 | twoway (line high date) /// 24 | (line low date) /// 25 | (line close date) /// 26 | (line open date) , /// 27 | title("Line graph with plottig scheme",justification(left) color(black) span pos(11)) 28 | 29 | * Have a lovely day! 30 | -------------------------------------------------------------------------------- /Library/line-uncluttered.html: -------------------------------------------------------------------------------- 1 | /* 2 | Figure: Line graph with uncluttered scheme 3 | 4 | Data Source: 5 | --------------------- 6 | Stata built-in dataset: uslifeexp 7 | 8 | Install Scheme (if needed): 9 | --------------------- 10 | Change scheme: scheme needs to be manually installed. Instruction on how 11 | to this can be found in https://gray.kimbrough.info/uncluttered-stata-graphs/ 12 | Step 1: go to https://gray.kimbrough.info/uncluttered-stata-graphs/ 13 | Step 2: click on "scheme" or go https://github.com/graykimbrough/uncluttered-stata-graphs/tree/master/schemes 14 | Step 3: Download two .scheme file in that github directionary 15 | Step 4: Place the .scheme file(s) in your Stata PERSONAL directory (if you dont know where, run "sysdir" in STATA Command) 16 | Step 5: run "set scheme uncluttered, permanent" in STATA Command 17 | 18 | 19 | */ 20 | 21 | sysuse uslifeexp, clear 22 | set scheme uncluttered 23 | 24 | line le le_male le_female year /// 25 | , /// 26 | ytitle(Life expectancy (years)) /// 27 | legend(on /// Scheme supresses the legend by default 28 | order(1 "Overall" /// Set label to show up in legend 29 | 2 "Male" /// 30 | 3 "Female") /// 31 | cols(3) /// Show all legends in one line (3 columns) 32 | pos(12)) /// Show legend on top of graph 33 | title("Line graph with uncluttered scheme", justification(left) color(black) span pos(11)) 34 | 35 | * Have a lovely Day! 36 | -------------------------------------------------------------------------------- /Library/map-world.html: -------------------------------------------------------------------------------- 1 | /* 2 | Figure: Map 3 | 4 | Data Source: 5 | -------------------------- 6 | Below codes are replicated from 7 | 8 | Joao Pedro Azevedo, 2011. "WBOPENDATA: Stata module to access World Bank databases," 9 | Statistical Software Components S457234, Boston College Department of Economics, revised 09 Jul 2020. 10 | 11 | The author Joao Pedro Azevedo also made available more examples using wbopendata available at https://github.com/jpazvd/wbopendata 12 | 13 | Install Packages (if needed): 14 | ---------------------------- 15 | We need one package to run this file: wbopendata 16 | Please remove "*" from below lines if you have not installed them and would like to install. 17 | 18 | */ 19 | * ssc install wbopendata, replace 20 | 21 | /// create a tempfile to store data mined from WDI using wbopendata 22 | qui tempfile WDIdata 23 | wbopendata, language(en - English) indicator(it.cel.sets.p2) long clear latest 24 | local labelvar "`r(varlabel1)'" 25 | sort countrycode 26 | save `WDIdata', replace 27 | 28 | /// create another tempfile from the world-c.dta which include X and Y coordinate of the country 29 | qui tempfile worldc 30 | qui sysuse world-c.dta, clear 31 | save `worldc'.dta, replace 32 | 33 | /// merge with world-d.dta which include areas of the country 34 | qui sysuse world-d.dta, clear 35 | qui merge countrycode using `WDIdata' 36 | qui sum year 37 | local avg = string(`r(mean)',"%16.1f") 38 | 39 | ///map out 40 | spmap it_cel_sets_p2 using `worldc' /// 41 | , id(_ID) clnumber(20) fcolor(Reds2) ocolor(none ..) /// 42 | title("`labelvar'", size(*1.2)) legstyle(3) legend(ring(1) position(3)) /// 43 | note("Source: World Development Indicator") 44 | 45 | * Have a lovely day! 46 | -------------------------------------------------------------------------------- /Library/reg-chartable.html: -------------------------------------------------------------------------------- 1 | /* 2 | Figure : Impact of provider qualifications on main standardized patient outcomes 3 | 4 | Data Source: 5 | -------------------------- 6 | 7 | Das, Jishnu, Liana Woskie, Ruma Rajbhandari, Kamran Abbasi, and Ashish Jha. 8 | “Rethinking assumptions about delivery of healthcare: implications for universal health coverage.” Bmj 361 (2018). 9 | 10 | Install Library (if needed): 11 | --------------------------- 12 | We need three packages to run this file: firthlogit, st0085_2 (estadd) , dm0037 (xml_tab) 13 | Please remove "*" from below lines if you have not installed them and would like to install. 14 | */ 15 | * ssc inst firthlogit 16 | * net from http://www.stata-journal.com/software/sj14-2 17 | * net install st0085_2 18 | * net from http://www.stata-journal.com/software/sj8-3 19 | * net install dm0037 20 | 21 | /// Load adofiles 22 | * These files are created by the authors for the purposes of this study and are not publicly available for general use. 23 | * These files are not guaranteed to produce appropriate statistics other than those contained in this replication file. 24 | 25 | qui do "https://github.com/worldbank/stata-visual-library/raw/master/Library/ado/chartablesheet.ado" 26 | 27 | use "https://github.com/worldbank/stata-visual-library/raw/master/Library/data/reg-chartable.dta", clear 28 | 29 | /// Sample Restriction Logic 30 | global cxr "& sp_case <3" 31 | global sputum "& sp_case <3" 32 | global sp_drugs_tb "& sp_case >2" 33 | 34 | /// Output 35 | chartable correct cxr sputum s5_referral sp_drugs_tb sp_drugs_antibio sp_drugs_quin /// 36 | using "results.xlsx" /// 37 | , /// 38 | c(xi: firthlogit) /// 39 | rhs(q_mbbs pro_age pro_male patients_waiting_in i.sp_id) or p globalif /// 40 | title("Impact of provider qualifications on main standardized patient outcomes", justification(left) color(black) span pos(11)) 41 | 42 | * Have a lovely day! 43 | -------------------------------------------------------------------------------- /Library/reg-het.html: -------------------------------------------------------------------------------- 1 | /* 2 | Figure: Marginal effects by heterogeneity groups 3 | 4 | Data Source: 5 | -------------------------- 6 | Use built-in data: auto 7 | */ 8 | sysuse auto, clear 9 | 10 | /// prepare option 11 | local label1 Foreign 12 | local label0 Domestic 13 | 14 | /// Supress y axis labels on graph to the right so it's only shown once on 15 | /// combined graph 16 | local yopts1 ylab(, labcolor(white)) /// 17 | ytitle("") /// 18 | yscale(noline) 19 | 20 | gr drop _all 21 | 22 | * install coefplot 23 | ssc install coefplot, replace 24 | 25 | /// create individual graph 26 | /// Loop over heterogeneity variables 27 | forvalues foreign = 0/1 { 28 | reg price mpg headroom if foreign == `foreign' /// Run regression to get margin effect 29 | 30 | /// Plot marginal effect by group 31 | coefplot /// 32 | , /// 33 | drop(_cons) /// don't show constant 34 | vertical /// 35 | yline(0, lpattern(dash)) /// for significance 36 | ciopt(color(gs10 gs10) /// 37 | recast(rcap)) /// 38 | levels(90 95) /// show 90% and 95% CIs 39 | ylab(, noticks glcolor(gs15)) /// 40 | xlab(, noticks labsize(small)) /// 41 | xtitle("") /// 42 | ytitle("Marginal effect on price") /// 43 | title(`label`foreign'', box bexpand bcolor(gs15)) /// add title in box 44 | color(black) /// 45 | name(f`foreign') /// 46 | graphregion(color(white)) /// 47 | `yopts`foreign'' 48 | } 49 | 50 | /// Combine graph 51 | gr combine f0 f1, /// 52 | ycommon /// 53 | graphregion(color(white)) /// 54 | title("Marginal effects by heterogeneity groups", justification(left) color(black) span pos(11)) 55 | 56 | 57 | * Have a lovely day! 58 | -------------------------------------------------------------------------------- /Library/reg-models.html: -------------------------------------------------------------------------------- 1 | /* 2 | Figure: Comparison of marginal effects from linear and logistic specifications 3 | 4 | Data Source: 5 | -------------------------- 6 | 7 | Satyanarayana S, Kwan A, Daniels B, Subbaraman R, McDowell A, Bergkvist S, Das RK, Das V, Das J, Pai M. 8 | Use of standardised patients to assess antibiotic dispensing for tuberculosis by pharmacies in urban India: A cross-sectional study. 9 | The Lancet Infectious Diseases. 2016 Nov 30;16(11):1261-8. 10 | 11 | Workflow explanation: 12 | The code takes the results from a linear regression and a logit regression 13 | and saves the coefficients, and the upper and lower bounds of the confidence 14 | intervals into a matrix (results). The twoway command will take the estimates 15 | and plot a comparison of marginal effects from the two specifications. 16 | */ 17 | 18 | global graph_opts title(, justification(left) color(black) span pos(11)) graphregion(color(white)) ylab(,angle(0) nogrid) xtit(,placement(left) justification(left)) yscale(noline) xscale(noline) legend(region(lc(none) fc(none))) 19 | 20 | use "https://github.com/worldbank/stata-visual-library/raw/master/Library/data/reg-models.dta" , clear 21 | 22 | cap mat drop theResults 23 | local theLabels "" 24 | local x = 15.5 25 | 26 | qui foreach var of varlist ??_correct refer med_any med_class_any_6 med_class_any_16 { 27 | 28 | local theLabel : var label `var' 29 | local theLabels `"`theLabels' `x' "`theLabel'""' 30 | local x = `x' - 2 31 | 32 | reg `var' facility_private i.case_code 33 | 34 | mat a = r(table) 35 | 36 | local b = a[1,1] 37 | local ll = a[5,1] 38 | local ul = a[6,1] 39 | mat a = [`b',`ll',`ul',1] 40 | mat rownames a = "`var'" 41 | 42 | logit `var' facility_private i.case_code 43 | margins , dydx(facility_private) 44 | 45 | mat b = r(table) 46 | 47 | local b = b[1,1] 48 | local ll = b[5,1] 49 | local ul = b[6,1] 50 | mat b = [`b',`ll',`ul',2] 51 | mat rownames b = "`var'" 52 | 53 | mat theResults = nullmat(theResults) \ a \ b 54 | } 55 | 56 | mat colnames theResults = "b" "ll" "ul" "type" 57 | matlist theResults 58 | 59 | clear 60 | svmat theResults , names(col) 61 | 62 | gen n = _n 63 | replace n = 17-n 64 | tw /// 65 | (rcap ll ul n if type == 1 , hor lc(navy)) /// 66 | (scatter n b if type == 1 , mc(black)) /// 67 | (rcap ll ul n if type == 2 , hor lc(maroon)) /// 68 | (scatter n b if type == 2 , mc(black)) /// 69 | , /// 70 | ${graph_opts} /// 71 | ylab(`theLabels') /// 72 | ytit(" ") /// 73 | xlab(-1 "-100p.p." -.5 `""-50p.p." "{&larr} Favors Public""' 0 "No Effect" .5 `""+50p.p." "Favors Private {&rarr}""' 1 "+100p.p.") /// 74 | xline(0 , lc(gs12) lp(dash)) /// 75 | legend(order(2 "Marginal Effect" 1 "Linear Model" 3 "Logistic Model") r(1)) /// 76 | title("Comparison of marginal effects", justification(left) color(black) span pos(11)) 77 | 78 | * Have a lovely day! 79 | -------------------------------------------------------------------------------- /Library/reg-predicted.html: -------------------------------------------------------------------------------- 1 | /* 2 | Figure: Adjusted prediction of car price with 95% confidence interval 3 | 4 | Data Source: 5 | -------------------------- 6 | Use built-in data: auto 7 | */ 8 | 9 | sysuse auto, clear 10 | 11 | reg price ibn.foreign 12 | 13 | /// Test if take up if the same across positive opportunity cost levels, then 14 | /// create and format local to add to the graph as text 15 | test 1.foreign == 0.foreign 16 | local pval : di %5.3f `r(p)' 17 | local pval = trim("`pval'") 18 | 19 | /// Calculate the predicted value for each category 20 | margins foreign 21 | 22 | * Create plot 23 | marginsplot, /// 24 | recast(bar) /// 25 | plotopts(barwidth(0.5) bargap(10)) /// 26 | ciopts(recast(rcap) color(gs10)) /// 27 | ylabel(0(2000)8000) /// 28 | title("Adjusted prediction of car price" "with 95% confidence interval", justification(center) color(black) span pos(17)) /// 29 | xlabel(, noticks) /// 30 | xtitle(Model origin) /// 31 | graphregion(color(white)) /// 32 | note(Note: P-value of F-test for coefficient equality across categories is `pval'.) 33 | 34 | * Have a lovely day! 35 | -------------------------------------------------------------------------------- /Library/scatter-fl-ci.html: -------------------------------------------------------------------------------- 1 | /* 2 | Figure : Make a scatter plot with confidence interval 3 | 4 | Data Source: 5 | -------------------------- 6 | Data replicated from: 7 | 8 | World Development Indicator 9 | */ 10 | 11 | use "https://github.com/worldbank/stata-visual-library/raw/develop/Library/data/scatter-fl-ci.dta", clear 12 | 13 | twoway (lfitci gdp_per_cap_growth morality_rate) /// 14 | (scatter gdp_per_cap_growth morality_rate if continent == "Europe & Central Asia", mcolor(cranberry) m(O) ) /// 15 | (scatter gdp_per_cap_growth morality_rate if continent == "South Asia", mcolor(dkgreen) m(D) ) /// 16 | (scatter gdp_per_cap_growth morality_rate if continent == "Middle East & North Africa", mcolor(ebblue ) m(T) ) /// 17 | (scatter gdp_per_cap_growth morality_rate if continent == "East Asia & Pacific", mcolor(dkorange) m(O)) /// 18 | (scatter gdp_per_cap_growth morality_rate if continent == "Sub-Saharan Africa", mcolor(navy) m(D) ) /// 19 | (scatter gdp_per_cap_growth morality_rate if continent == "Latin America & Caribbean", mcolor(red) m(T)) /// 20 | (scatter gdp_per_cap_growth morality_rate if continent == "North Amercia", mcolor(yellow) m(D)) /// 21 | , /// 22 | xlabel(0(20)120) /// 23 | xtitle("Morality Rate under 5 (Per 1,000 lives) ", axis(1)) /// 24 | ylabel(-10(5)25) /// 25 | ytitle("Annual GDP per Capita Growth Rate (%)" ) /// 26 | legend(order( 3 4 5 6 7 8 9) label(3 "East Asia & Pacific") label(4 "Europe & Central Asia") /// 27 | label(5 "Latin America & Caribbean") label(6 "Middle East & North Africa") label(7 "North America") /// 28 | label(8 "South America") label(9 "Sub-Saharan Africa") /// 29 | ring(0) position(1)) /// 30 | title("Morality Rate under 5 and GDP per Capita Growth " "Correlation") /// 31 | note("Source: World Development Indicatior (2019)") /// 32 | graphregion(color(white)) bgcolor(white) 33 | 34 | * Have a lovely day! 35 | -------------------------------------------------------------------------------- /Library/scatter-fl.html: -------------------------------------------------------------------------------- 1 | *Figure: scatter plot with fitted line 2 | 3 | * Load data 4 | * --------- 5 | sysuse auto, clear 6 | 7 | * Set graph options 8 | * ---- 9 | local col_domestic midblue 10 | local col_foreign red 11 | local transparency %30 12 | local point_width 0 13 | local point_size small 14 | 15 | * Plot 16 | * ---- 17 | twoway (scatter price mpg if foreign == 0, mfcolor(`col_domestic'`transparency') msize(`point_size') mlwidth(`point_width')) /// 18 | (lfit price mpg if foreign == 0, color(`col_domestic')) /// 19 | (scatter price mpg if foreign == 1, mfcolor(`col_foreign'`transparency') msize(`point_size') mlwidth(`point_width')) /// 20 | (lfit price mpg if foreign == 1, color(`col_foreign')) /// 21 | , /// 22 | graphregion(color(white)) /// 23 | legend(order(2 "Domestic" 4 "Foreign")) 24 | 25 | -------------------------------------------------------------------------------- /Library/scatter-poly-ci.html: -------------------------------------------------------------------------------- 1 | /* 2 | Figure: Scatter plot with polynomial smoothing and confidence interval 3 | 4 | Data Source: 5 | -------------------------- 6 | Data replicated from: 7 | 8 | Christian, Paul, and Brian Dillon. 2018. “Growing and Learning When Consumption Is Seasonal: 9 | Long-Term Evidence From Tanzania.” Demography 55 (3): 1091–1118. doi:10.1007/s13524-018-0669-4. 10 | 11 | with some noises being added 12 | 13 | Install Packages (if needed) 14 | ---------------------------- 15 | We need one package to run this file: grc1leg 16 | Please remove "*" from below lines if you have not installed it and would like to install. 17 | */ 18 | 19 | * net from http://www.stata.com 20 | * net cd users 21 | * net cd vwiggins 22 | * net install grc1leg 23 | 24 | /// Load data 25 | use "https://github.com/worldbank/stata-visual-library/raw/master/Library/data/scatter-poly-ci.dta", clear 26 | 27 | /// Create First Graph 28 | sum cons_pae_m_sine, det 29 | 30 | twoway (scatter cons_pae_sd_sine cons_pae_m_sine if cons_pae_m_sine < `r(p99)') /// 31 | (lpolyci cons_pae_sd_sine cons_pae_m_sine if cons_pae_m_sine < `r(p99)') /// 32 | , /// 33 | legend(off) /// 34 | xtitle(" " "`=ustrunescape("\u006D\u0302")'", size(large)) /// m-hat 35 | ytitle("`=ustrunescape("\u0073\u0302")'" " ", size(large)) /// s-hat 36 | xlabel(50 "50" 100 "100" 150 "150" 200 "200") /// 37 | graphregion(color(white)) bgcolor(white) /// 38 | name(s_by_mhat) 39 | 40 | /// Create Second Graph 41 | sum cons_pae_m_sine, det 42 | twoway (scatter cv cons_pae_m_sine if cons_pae_m_sine<`r(p99)' & cons_pae_m_sine>`r(p1)') /// 43 | (lpolyci cv cons_pae_m_sine if cons_pae_m_sine<`r(p99)' & cons_pae_m_sine>`r(p1)') /// 44 | , /// 45 | ytitle("`=ustrunescape("\u0073\u0302/\u006D\u0302")'" " ", size(large)) /// s-hat/m-hat 46 | xtitle(" " "`=ustrunescape("\u006D\u0302")'", size(large)) /// m-hat 47 | legend(order(2 3) label(3 "Local Poly.") label(2 "95% CI")) /// 48 | graphregion(color(white)) bgcolor(white) /// 49 | name(cv_by_mhat) 50 | 51 | /// Combine graphs 52 | grc1leg s_by_mhat cv_by_mhat /// 53 | , /// 54 | row(1) legendfrom(cv_by_mhat) /// 55 | imargin(0 0 0 0) graphregion(margin(t=0 b=0)) /// 56 | position(6) fysize(75) fxsize(150) /// 57 | graphregion(color(white)) plotregion(color(white)) /// 58 | title("Scatter plot with polynomial smoothing" "and confidence interval", justification(center) color(black) span pos(17)) 59 | 60 | * Have a lovely day! 61 | -------------------------------------------------------------------------------- /Library/scatter-strata.html: -------------------------------------------------------------------------------- 1 | /* 2 | Figure: Regression Coefficient plot 3 | 4 | Data Source: 5 | -------------------------- 6 | Data replicated from: 7 | 8 | Das, Jishnu, Liana Woskie, Ruma Rajbhandari, Kamran Abbasi, and Ashish Jha. 9 | “Rethinking assumptions about delivery of healthcare: implications for universal health coverage.” Bmj 361 (2018). 10 | 11 | 12 | Install Packages (if needed) 13 | ---------------------------- 14 | We need three packages to run this file: firthlogit, st0085_2 (estadd) , dm0037 (xml_tab) 15 | Please remove "*" from below lines if you have not installed it and would like to install. 16 | */ 17 | 18 | * ssc inst firthlogit 19 | * net from http://www.stata-journal.com/software/sj14-2 20 | * net install st0085_2 21 | * net from http://www.stata-journal.com/software/sj8-3 22 | * net install dm0037 23 | 24 | run "https://raw.githubusercontent.com/worldbank/stata-visual-library/master/Library/ado/freeshape.ado" 25 | run "https://raw.githubusercontent.com/worldbank/stata-visual-library/master/Library/ado/labelcollapse.ado" 26 | 27 | /// Load data 28 | use "https://github.com/worldbank/stata-visual-library/raw/master/Library/data/scatter-strata.dta", clear 29 | 30 | /// Collapse and reshape data 31 | labelcollapse essential correct cxr sputum dstgx s5_referral sp_drugs_tb sp_drugs_antibio sp_drugs_quin, by(sp_case) 32 | freeshape essential correct cxr sputum dstgx s5_referral sp_drugs_tb sp_drugs_antibio sp_drugs_quin, i(sp_case) j(var) 33 | 34 | /// Assign ordered number 35 | local x = 1 36 | gen order = 0 37 | 38 | qui foreach name in essential correct cxr sputum dstgx s5_referral sp_drugs_tb sp_drugs_antibio sp_drugs_quin { 39 | replace order = `x' if var_name == "`name'" 40 | local ++x 41 | } 42 | 43 | /// Create graph 44 | graph dot var_value /// 45 | , /// 46 | asy over(sp_case) over(var_label, sort(order)) /// 47 | linegap(20) /// 48 | graphregion(color(white)) /// 49 | xsize(7) /// 50 | legend(region(lc(none) fc(none))) /// 51 | yscale(noline) ytit("") ylab(0 "0%" .25 "25%" .5 "50%" .75 "75%" 1 "100%") /// 52 | linetype(line) lines( lp(.) lc(gs11)) /// 53 | legend(pos(5) ring(0) c(1) region(lc(white) fc(white))) /// 54 | marker(1, m(O) mlcolor(black)) /// 55 | marker(2, m(O) mlcolor(black)) /// 56 | marker(3, m(O) mlcolor(black)) /// 57 | marker(4, m(O) mlcolor(black)) /// 58 | title("Regression Coefficient plot", justification(center) color(black) span pos(17)) 59 | 60 | * Have a good day! 61 | -------------------------------------------------------------------------------- /Library/scatter-transparent.html: -------------------------------------------------------------------------------- 1 | /* 2 | Figure: Scatter plot with transparent points 3 | 4 | Data Source: 5 | -------------------------- 6 | Use built-in data: auto 7 | */ 8 | 9 | sysuse auto, clear 10 | 11 | scatter /// 12 | price mpg /// 13 | , /// 14 | mcolor(midblue%50) /// the value after % sets the transparency 15 | mlwidth(0) /// set width of border to 0 16 | graphregion(color(white)) /// 17 | title("Scatter plot with transparent points", justification(center) color(black) span pos(17)) 18 | 19 | * Have a lovely day! 20 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # stata-visual-library 2 | This is a repository maintained by DIME Analytics and containing example graphs on how to explore data sets and display results of Impact Evaluations using Stata. 3 | -------------------------------------------------------------------------------- /docs/BarPlots.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | Stata Visual Library 13 | 14 | 18 | 19 | 23 | 24 | 25 | 26 | 27 | 33 | 34 | 39 | 40 | 45 | 46 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 |
63 | 64 | 65 |
66 |
67 | 80 |
81 |
82 | 83 | 88 | 93 | 94 | 95 | 96 | -------------------------------------------------------------------------------- /docs/BoxPlots.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | Stata Visual Library 13 | 14 | 18 | 19 | 23 | 24 | 25 | 26 | 27 | 33 | 34 | 39 | 40 | 45 | 46 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 |
63 | 64 | 65 |
66 |
67 | 80 |
81 |
82 | 83 | 88 | 93 | 94 | 95 | 96 | -------------------------------------------------------------------------------- /docs/DensityPlots.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | Stata Visual Library 13 | 14 | 18 | 19 | 23 | 24 | 25 | 26 | 27 | 33 | 34 | 39 | 40 | 45 | 46 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 |
63 | 64 | 65 |
66 |
67 | 80 |
81 |
82 | 83 | 88 | 93 | 94 | 95 | 96 | -------------------------------------------------------------------------------- /docs/EventStudy.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | Stata Visual Library 13 | 14 | 18 | 19 | 23 | 24 | 25 | 26 | 27 | 33 | 34 | 39 | 40 | 45 | 46 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 |
63 | 64 | 65 |
66 |
67 | 80 |
81 |
82 | 83 | 88 | 93 | 94 | 95 | 96 | -------------------------------------------------------------------------------- /docs/LinePlots.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | Stata Visual Library 13 | 14 | 18 | 19 | 23 | 24 | 25 | 26 | 27 | 33 | 34 | 39 | 40 | 45 | 46 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 |
63 | 64 | 65 |
66 |
67 | 80 |
81 |
82 | 83 | 88 | 93 | 94 | 95 | 96 | -------------------------------------------------------------------------------- /docs/Map.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | Stata Visual Library 13 | 14 | 18 | 19 | 23 | 24 | 25 | 26 | 27 | 33 | 34 | 39 | 40 | 45 | 46 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 |
63 | 64 | 65 |
66 |
67 | 80 |
81 |
82 | 83 | 88 | 93 | 94 | 95 | 96 | -------------------------------------------------------------------------------- /docs/Maps.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | Stata Visual Library 13 | 14 | 18 | 19 | 23 | 24 | 25 | 26 | 27 | 33 | 34 | 39 | 40 | 45 | 46 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 |
63 | 64 | 65 |
66 | 79 |
80 | 81 | 86 | 91 | 92 | 93 | 94 | -------------------------------------------------------------------------------- /docs/RegressionCoef.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | Stata Visual Library 13 | 14 | 18 | 19 | 23 | 24 | 25 | 26 | 27 | 33 | 34 | 39 | 40 | 45 | 46 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 |
63 | 64 | 65 |
66 |
67 | 80 |
81 |
82 | 83 | 88 | 93 | 94 | 95 | 96 | -------------------------------------------------------------------------------- /docs/ScatterPlots.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | Stata Visual Library 13 | 14 | 18 | 19 | 23 | 24 | 25 | 26 | 27 | 33 | 34 | 39 | 40 | 45 | 46 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 |
63 | 64 | 65 |
66 |
67 | 80 |
81 |
82 | 83 | 88 | 93 | 94 | 95 | 96 | -------------------------------------------------------------------------------- /docs/bar-over.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | Stata Visual Library 13 | 14 | 18 | 19 | 20 | 21 | 22 | 28 | 29 | 34 | 35 | 36 | 45 | 46 | 51 | 52 | 53 | 62 | 63 | 72 | 73 | bar-over 74 | 80 | 83 | 84 | 85 | 86 | 87 | 88 | 89 |
90 | 91 | 92 |
93 | 94 |
 
 95 |       
96 |
97 |
98 | 99 | 100 | 101 | 102 | 107 | 112 | 113 | 114 | -------------------------------------------------------------------------------- /docs/figure/bar-better-ci.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/worldbank/stata-visual-library/552f4353761c3d37f8e1f6cbe671ca5271dc67e7/docs/figure/bar-better-ci.png -------------------------------------------------------------------------------- /docs/figure/bar-better.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/worldbank/stata-visual-library/552f4353761c3d37f8e1f6cbe671ca5271dc67e7/docs/figure/bar-better.png -------------------------------------------------------------------------------- /docs/figure/bar-betterbar.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/worldbank/stata-visual-library/552f4353761c3d37f8e1f6cbe671ca5271dc67e7/docs/figure/bar-betterbar.png -------------------------------------------------------------------------------- /docs/figure/bar-counts.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/worldbank/stata-visual-library/552f4353761c3d37f8e1f6cbe671ca5271dc67e7/docs/figure/bar-counts.png -------------------------------------------------------------------------------- /docs/figure/bar-custombar.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/worldbank/stata-visual-library/552f4353761c3d37f8e1f6cbe671ca5271dc67e7/docs/figure/bar-custombar.png -------------------------------------------------------------------------------- /docs/figure/bar-over.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/worldbank/stata-visual-library/552f4353761c3d37f8e1f6cbe671ca5271dc67e7/docs/figure/bar-over.png -------------------------------------------------------------------------------- /docs/figure/bar-stack-by.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/worldbank/stata-visual-library/552f4353761c3d37f8e1f6cbe671ca5271dc67e7/docs/figure/bar-stack-by.png -------------------------------------------------------------------------------- /docs/figure/bar-stack-cat.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/worldbank/stata-visual-library/552f4353761c3d37f8e1f6cbe671ca5271dc67e7/docs/figure/bar-stack-cat.png -------------------------------------------------------------------------------- /docs/figure/bar-two-axes.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/worldbank/stata-visual-library/552f4353761c3d37f8e1f6cbe671ca5271dc67e7/docs/figure/bar-two-axes.png -------------------------------------------------------------------------------- /docs/figure/bar-weightab.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/worldbank/stata-visual-library/552f4353761c3d37f8e1f6cbe671ca5271dc67e7/docs/figure/bar-weightab.png -------------------------------------------------------------------------------- /docs/figure/binned-scatter.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/worldbank/stata-visual-library/552f4353761c3d37f8e1f6cbe671ca5271dc67e7/docs/figure/binned-scatter.png -------------------------------------------------------------------------------- /docs/figure/boxplot-pctile.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/worldbank/stata-visual-library/552f4353761c3d37f8e1f6cbe671ca5271dc67e7/docs/figure/boxplot-pctile.png -------------------------------------------------------------------------------- /docs/figure/cheatsheet.PNG: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/worldbank/stata-visual-library/552f4353761c3d37f8e1f6cbe671ca5271dc67e7/docs/figure/cheatsheet.PNG -------------------------------------------------------------------------------- /docs/figure/confidence-intervals.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/worldbank/stata-visual-library/552f4353761c3d37f8e1f6cbe671ca5271dc67e7/docs/figure/confidence-intervals.png -------------------------------------------------------------------------------- /docs/figure/density-av.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/worldbank/stata-visual-library/552f4353761c3d37f8e1f6cbe671ca5271dc67e7/docs/figure/density-av.png -------------------------------------------------------------------------------- /docs/figure/density-data.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/worldbank/stata-visual-library/552f4353761c3d37f8e1f6cbe671ca5271dc67e7/docs/figure/density-data.png -------------------------------------------------------------------------------- /docs/figure/density-shaded.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/worldbank/stata-visual-library/552f4353761c3d37f8e1f6cbe671ca5271dc67e7/docs/figure/density-shaded.png -------------------------------------------------------------------------------- /docs/figure/dimewiki.PNG: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/worldbank/stata-visual-library/552f4353761c3d37f8e1f6cbe671ca5271dc67e7/docs/figure/dimewiki.PNG -------------------------------------------------------------------------------- /docs/figure/dot-summary.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/worldbank/stata-visual-library/552f4353761c3d37f8e1f6cbe671ca5271dc67e7/docs/figure/dot-summary.png -------------------------------------------------------------------------------- /docs/figure/drip.PNG: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/worldbank/stata-visual-library/552f4353761c3d37f8e1f6cbe671ca5271dc67e7/docs/figure/drip.PNG -------------------------------------------------------------------------------- /docs/figure/eventstudy-prepost.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/worldbank/stata-visual-library/552f4353761c3d37f8e1f6cbe671ca5271dc67e7/docs/figure/eventstudy-prepost.png -------------------------------------------------------------------------------- /docs/figure/grstyle.PNG: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/worldbank/stata-visual-library/552f4353761c3d37f8e1f6cbe671ca5271dc67e7/docs/figure/grstyle.PNG -------------------------------------------------------------------------------- /docs/figure/iefieldkit.PNG: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/worldbank/stata-visual-library/552f4353761c3d37f8e1f6cbe671ca5271dc67e7/docs/figure/iefieldkit.PNG -------------------------------------------------------------------------------- /docs/figure/ietoolkit.PNG: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/worldbank/stata-visual-library/552f4353761c3d37f8e1f6cbe671ca5271dc67e7/docs/figure/ietoolkit.PNG -------------------------------------------------------------------------------- /docs/figure/line-fit-text.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/worldbank/stata-visual-library/552f4353761c3d37f8e1f6cbe671ca5271dc67e7/docs/figure/line-fit-text.png -------------------------------------------------------------------------------- /docs/figure/line-plottig.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/worldbank/stata-visual-library/552f4353761c3d37f8e1f6cbe671ca5271dc67e7/docs/figure/line-plottig.png -------------------------------------------------------------------------------- /docs/figure/line-uncluttered.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/worldbank/stata-visual-library/552f4353761c3d37f8e1f6cbe671ca5271dc67e7/docs/figure/line-uncluttered.png -------------------------------------------------------------------------------- /docs/figure/map-world.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/worldbank/stata-visual-library/552f4353761c3d37f8e1f6cbe671ca5271dc67e7/docs/figure/map-world.png -------------------------------------------------------------------------------- /docs/figure/official.PNG: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/worldbank/stata-visual-library/552f4353761c3d37f8e1f6cbe671ca5271dc67e7/docs/figure/official.PNG -------------------------------------------------------------------------------- /docs/figure/practices.PNG: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/worldbank/stata-visual-library/552f4353761c3d37f8e1f6cbe671ca5271dc67e7/docs/figure/practices.PNG -------------------------------------------------------------------------------- /docs/figure/r.PNG: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/worldbank/stata-visual-library/552f4353761c3d37f8e1f6cbe671ca5271dc67e7/docs/figure/r.PNG -------------------------------------------------------------------------------- /docs/figure/rd.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/worldbank/stata-visual-library/552f4353761c3d37f8e1f6cbe671ca5271dc67e7/docs/figure/rd.png -------------------------------------------------------------------------------- /docs/figure/reg-chartable.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/worldbank/stata-visual-library/552f4353761c3d37f8e1f6cbe671ca5271dc67e7/docs/figure/reg-chartable.png -------------------------------------------------------------------------------- /docs/figure/reg-het.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/worldbank/stata-visual-library/552f4353761c3d37f8e1f6cbe671ca5271dc67e7/docs/figure/reg-het.png -------------------------------------------------------------------------------- /docs/figure/reg-models.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/worldbank/stata-visual-library/552f4353761c3d37f8e1f6cbe671ca5271dc67e7/docs/figure/reg-models.png -------------------------------------------------------------------------------- /docs/figure/reg-predicted.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/worldbank/stata-visual-library/552f4353761c3d37f8e1f6cbe671ca5271dc67e7/docs/figure/reg-predicted.png -------------------------------------------------------------------------------- /docs/figure/regression-fit.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/worldbank/stata-visual-library/552f4353761c3d37f8e1f6cbe671ca5271dc67e7/docs/figure/regression-fit.png -------------------------------------------------------------------------------- /docs/figure/scatter-fl-ci.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/worldbank/stata-visual-library/552f4353761c3d37f8e1f6cbe671ca5271dc67e7/docs/figure/scatter-fl-ci.png -------------------------------------------------------------------------------- /docs/figure/scatter-fl.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/worldbank/stata-visual-library/552f4353761c3d37f8e1f6cbe671ca5271dc67e7/docs/figure/scatter-fl.png -------------------------------------------------------------------------------- /docs/figure/scatter-poly-ci.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/worldbank/stata-visual-library/552f4353761c3d37f8e1f6cbe671ca5271dc67e7/docs/figure/scatter-poly-ci.png -------------------------------------------------------------------------------- /docs/figure/scatter-strata.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/worldbank/stata-visual-library/552f4353761c3d37f8e1f6cbe671ca5271dc67e7/docs/figure/scatter-strata.png -------------------------------------------------------------------------------- /docs/figure/scatter-transparent.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/worldbank/stata-visual-library/552f4353761c3d37f8e1f6cbe671ca5271dc67e7/docs/figure/scatter-transparent.png -------------------------------------------------------------------------------- /docs/figure/sdas.PNG: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/worldbank/stata-visual-library/552f4353761c3d37f8e1f6cbe671ca5271dc67e7/docs/figure/sdas.PNG -------------------------------------------------------------------------------- /docs/figure/visual-overview.PNG: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/worldbank/stata-visual-library/552f4353761c3d37f8e1f6cbe671ca5271dc67e7/docs/figure/visual-overview.PNG -------------------------------------------------------------------------------- /docs/header.html: -------------------------------------------------------------------------------- 1 | 2 |
3 | 4 | 5 |
6 |
7 |

Stata Visual Library

8 |

Inspiration and code for data visualization in Stata, created and maintained by DIME Analytics.

9 |
10 |
11 | 12 | 13 |
54 | -------------------------------------------------------------------------------- /docs/reg-het.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | Stata Visual Library 13 | 14 | 18 | 19 | 20 | 21 | 22 | 28 | 29 | 34 | 35 | 36 | 45 | 46 | 51 | 52 | 53 | 62 | 63 | 72 | 73 | reg-het 74 | 80 | 83 | 84 | 85 | 86 | 87 | 88 | 89 |
90 | 91 | 92 |
93 | 94 |
 
 95 |       
96 |
97 |
98 | 99 | 100 | 101 | 102 | 107 | 112 | 113 | 114 | -------------------------------------------------------------------------------- /docs/site_libs/bootstrap-3.3.5/css/fonts/Lato.ttf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/worldbank/stata-visual-library/552f4353761c3d37f8e1f6cbe671ca5271dc67e7/docs/site_libs/bootstrap-3.3.5/css/fonts/Lato.ttf -------------------------------------------------------------------------------- /docs/site_libs/bootstrap-3.3.5/css/fonts/LatoBold.ttf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/worldbank/stata-visual-library/552f4353761c3d37f8e1f6cbe671ca5271dc67e7/docs/site_libs/bootstrap-3.3.5/css/fonts/LatoBold.ttf -------------------------------------------------------------------------------- /docs/site_libs/bootstrap-3.3.5/css/fonts/LatoItalic.ttf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/worldbank/stata-visual-library/552f4353761c3d37f8e1f6cbe671ca5271dc67e7/docs/site_libs/bootstrap-3.3.5/css/fonts/LatoItalic.ttf -------------------------------------------------------------------------------- /docs/site_libs/bootstrap-3.3.5/css/fonts/NewsCycle.ttf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/worldbank/stata-visual-library/552f4353761c3d37f8e1f6cbe671ca5271dc67e7/docs/site_libs/bootstrap-3.3.5/css/fonts/NewsCycle.ttf -------------------------------------------------------------------------------- /docs/site_libs/bootstrap-3.3.5/css/fonts/NewsCycleBold.ttf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/worldbank/stata-visual-library/552f4353761c3d37f8e1f6cbe671ca5271dc67e7/docs/site_libs/bootstrap-3.3.5/css/fonts/NewsCycleBold.ttf -------------------------------------------------------------------------------- /docs/site_libs/bootstrap-3.3.5/css/fonts/OpenSans.ttf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/worldbank/stata-visual-library/552f4353761c3d37f8e1f6cbe671ca5271dc67e7/docs/site_libs/bootstrap-3.3.5/css/fonts/OpenSans.ttf -------------------------------------------------------------------------------- /docs/site_libs/bootstrap-3.3.5/css/fonts/OpenSansBold.ttf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/worldbank/stata-visual-library/552f4353761c3d37f8e1f6cbe671ca5271dc67e7/docs/site_libs/bootstrap-3.3.5/css/fonts/OpenSansBold.ttf -------------------------------------------------------------------------------- /docs/site_libs/bootstrap-3.3.5/css/fonts/OpenSansBoldItalic.ttf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/worldbank/stata-visual-library/552f4353761c3d37f8e1f6cbe671ca5271dc67e7/docs/site_libs/bootstrap-3.3.5/css/fonts/OpenSansBoldItalic.ttf -------------------------------------------------------------------------------- /docs/site_libs/bootstrap-3.3.5/css/fonts/OpenSansItalic.ttf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/worldbank/stata-visual-library/552f4353761c3d37f8e1f6cbe671ca5271dc67e7/docs/site_libs/bootstrap-3.3.5/css/fonts/OpenSansItalic.ttf -------------------------------------------------------------------------------- /docs/site_libs/bootstrap-3.3.5/css/fonts/OpenSansLight.ttf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/worldbank/stata-visual-library/552f4353761c3d37f8e1f6cbe671ca5271dc67e7/docs/site_libs/bootstrap-3.3.5/css/fonts/OpenSansLight.ttf -------------------------------------------------------------------------------- /docs/site_libs/bootstrap-3.3.5/css/fonts/OpenSansLightItalic.ttf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/worldbank/stata-visual-library/552f4353761c3d37f8e1f6cbe671ca5271dc67e7/docs/site_libs/bootstrap-3.3.5/css/fonts/OpenSansLightItalic.ttf -------------------------------------------------------------------------------- /docs/site_libs/bootstrap-3.3.5/css/fonts/Raleway.ttf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/worldbank/stata-visual-library/552f4353761c3d37f8e1f6cbe671ca5271dc67e7/docs/site_libs/bootstrap-3.3.5/css/fonts/Raleway.ttf -------------------------------------------------------------------------------- /docs/site_libs/bootstrap-3.3.5/css/fonts/RalewayBold.ttf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/worldbank/stata-visual-library/552f4353761c3d37f8e1f6cbe671ca5271dc67e7/docs/site_libs/bootstrap-3.3.5/css/fonts/RalewayBold.ttf -------------------------------------------------------------------------------- /docs/site_libs/bootstrap-3.3.5/css/fonts/Roboto.ttf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/worldbank/stata-visual-library/552f4353761c3d37f8e1f6cbe671ca5271dc67e7/docs/site_libs/bootstrap-3.3.5/css/fonts/Roboto.ttf -------------------------------------------------------------------------------- /docs/site_libs/bootstrap-3.3.5/css/fonts/RobotoBold.ttf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/worldbank/stata-visual-library/552f4353761c3d37f8e1f6cbe671ca5271dc67e7/docs/site_libs/bootstrap-3.3.5/css/fonts/RobotoBold.ttf -------------------------------------------------------------------------------- /docs/site_libs/bootstrap-3.3.5/css/fonts/RobotoLight.ttf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/worldbank/stata-visual-library/552f4353761c3d37f8e1f6cbe671ca5271dc67e7/docs/site_libs/bootstrap-3.3.5/css/fonts/RobotoLight.ttf -------------------------------------------------------------------------------- /docs/site_libs/bootstrap-3.3.5/css/fonts/RobotoMedium.ttf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/worldbank/stata-visual-library/552f4353761c3d37f8e1f6cbe671ca5271dc67e7/docs/site_libs/bootstrap-3.3.5/css/fonts/RobotoMedium.ttf -------------------------------------------------------------------------------- /docs/site_libs/bootstrap-3.3.5/css/fonts/SourceSansPro.ttf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/worldbank/stata-visual-library/552f4353761c3d37f8e1f6cbe671ca5271dc67e7/docs/site_libs/bootstrap-3.3.5/css/fonts/SourceSansPro.ttf -------------------------------------------------------------------------------- /docs/site_libs/bootstrap-3.3.5/css/fonts/SourceSansProBold.ttf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/worldbank/stata-visual-library/552f4353761c3d37f8e1f6cbe671ca5271dc67e7/docs/site_libs/bootstrap-3.3.5/css/fonts/SourceSansProBold.ttf -------------------------------------------------------------------------------- /docs/site_libs/bootstrap-3.3.5/css/fonts/SourceSansProItalic.ttf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/worldbank/stata-visual-library/552f4353761c3d37f8e1f6cbe671ca5271dc67e7/docs/site_libs/bootstrap-3.3.5/css/fonts/SourceSansProItalic.ttf -------------------------------------------------------------------------------- /docs/site_libs/bootstrap-3.3.5/css/fonts/SourceSansProLight.ttf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/worldbank/stata-visual-library/552f4353761c3d37f8e1f6cbe671ca5271dc67e7/docs/site_libs/bootstrap-3.3.5/css/fonts/SourceSansProLight.ttf -------------------------------------------------------------------------------- /docs/site_libs/bootstrap-3.3.5/css/fonts/Ubuntu.ttf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/worldbank/stata-visual-library/552f4353761c3d37f8e1f6cbe671ca5271dc67e7/docs/site_libs/bootstrap-3.3.5/css/fonts/Ubuntu.ttf -------------------------------------------------------------------------------- /docs/site_libs/bootstrap-3.3.5/fonts/glyphicons-halflings-regular.eot: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/worldbank/stata-visual-library/552f4353761c3d37f8e1f6cbe671ca5271dc67e7/docs/site_libs/bootstrap-3.3.5/fonts/glyphicons-halflings-regular.eot -------------------------------------------------------------------------------- /docs/site_libs/bootstrap-3.3.5/fonts/glyphicons-halflings-regular.ttf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/worldbank/stata-visual-library/552f4353761c3d37f8e1f6cbe671ca5271dc67e7/docs/site_libs/bootstrap-3.3.5/fonts/glyphicons-halflings-regular.ttf -------------------------------------------------------------------------------- /docs/site_libs/bootstrap-3.3.5/fonts/glyphicons-halflings-regular.woff: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/worldbank/stata-visual-library/552f4353761c3d37f8e1f6cbe671ca5271dc67e7/docs/site_libs/bootstrap-3.3.5/fonts/glyphicons-halflings-regular.woff -------------------------------------------------------------------------------- /docs/site_libs/bootstrap-3.3.5/fonts/glyphicons-halflings-regular.woff2: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/worldbank/stata-visual-library/552f4353761c3d37f8e1f6cbe671ca5271dc67e7/docs/site_libs/bootstrap-3.3.5/fonts/glyphicons-halflings-regular.woff2 -------------------------------------------------------------------------------- /docs/site_libs/bootstrap-3.3.5/shim/html5shiv.min.js: -------------------------------------------------------------------------------- 1 | /** 2 | * @preserve HTML5 Shiv 3.7.2 | @afarkas @jdalton @jon_neal @rem | MIT/GPL2 Licensed 3 | */ 4 | // Only run this code in IE 8 5 | if (!!window.navigator.userAgent.match("MSIE 8")) { 6 | !function(a,b){function c(a,b){var c=a.createElement("p"),d=a.getElementsByTagName("head")[0]||a.documentElement;return c.innerHTML="x",d.insertBefore(c.lastChild,d.firstChild)}function d(){var a=t.elements;return"string"==typeof a?a.split(" "):a}function e(a,b){var c=t.elements;"string"!=typeof c&&(c=c.join(" ")),"string"!=typeof a&&(a=a.join(" ")),t.elements=c+" "+a,j(b)}function f(a){var b=s[a[q]];return b||(b={},r++,a[q]=r,s[r]=b),b}function g(a,c,d){if(c||(c=b),l)return c.createElement(a);d||(d=f(c));var e;return e=d.cache[a]?d.cache[a].cloneNode():p.test(a)?(d.cache[a]=d.createElem(a)).cloneNode():d.createElem(a),!e.canHaveChildren||o.test(a)||e.tagUrn?e:d.frag.appendChild(e)}function h(a,c){if(a||(a=b),l)return a.createDocumentFragment();c=c||f(a);for(var e=c.frag.cloneNode(),g=0,h=d(),i=h.length;i>g;g++)e.createElement(h[g]);return e}function i(a,b){b.cache||(b.cache={},b.createElem=a.createElement,b.createFrag=a.createDocumentFragment,b.frag=b.createFrag()),a.createElement=function(c){return t.shivMethods?g(c,a,b):b.createElem(c)},a.createDocumentFragment=Function("h,f","return function(){var n=f.cloneNode(),c=n.createElement;h.shivMethods&&("+d().join().replace(/[\w\-:]+/g,function(a){return b.createElem(a),b.frag.createElement(a),'c("'+a+'")'})+");return n}")(t,b.frag)}function j(a){a||(a=b);var d=f(a);return!t.shivCSS||k||d.hasCSS||(d.hasCSS=!!c(a,"article,aside,dialog,figcaption,figure,footer,header,hgroup,main,nav,section{display:block}mark{background:#FF0;color:#000}template{display:none}")),l||i(a,d),a}var k,l,m="3.7.2",n=a.html5||{},o=/^<|^(?:button|map|select|textarea|object|iframe|option|optgroup)$/i,p=/^(?:a|b|code|div|fieldset|h1|h2|h3|h4|h5|h6|i|label|li|ol|p|q|span|strong|style|table|tbody|td|th|tr|ul)$/i,q="_html5shiv",r=0,s={};!function(){try{var a=b.createElement("a");a.innerHTML="",k="hidden"in a,l=1==a.childNodes.length||function(){b.createElement("a");var a=b.createDocumentFragment();return"undefined"==typeof a.cloneNode||"undefined"==typeof a.createDocumentFragment||"undefined"==typeof a.createElement}()}catch(c){k=!0,l=!0}}();var t={elements:n.elements||"abbr article aside audio bdi canvas data datalist details dialog figcaption figure footer header hgroup main mark meter nav output picture progress section summary template time video",version:m,shivCSS:n.shivCSS!==!1,supportsUnknownElements:l,shivMethods:n.shivMethods!==!1,type:"default",shivDocument:j,createElement:g,createDocumentFragment:h,addElements:e};a.html5=t,j(b)}(this,document); 7 | }; 8 | -------------------------------------------------------------------------------- /docs/site_libs/custom-css.css: -------------------------------------------------------------------------------- 1 | h1 { 2 | font-size: 34px; 3 | } 4 | h3 { 5 | text-align: left; 6 | color: #333; 7 | padding: 10px 0px; 8 | font: 14px bold Verdana, sans-serif; 9 | font-weight: bold; 10 | margin-top: 14px; 11 | } 12 | .main-container { 13 | max-width: 1150px; 14 | margin-left: auto; 15 | margin-right: auto; 16 | } 17 | img { 18 | max-width:90%; 19 | display: block; 20 | margin-left: auto; 21 | margin-right: auto; 22 | } 23 | .card { 24 | margin-bottom: 20px; 25 | } 26 | .navbar-custom { 27 | background-color: #008080; 28 | color: #ededed; 29 | } 30 | .jumbotron { 31 | background-color: #009a9a; 32 | color: #ffffff; 33 | padding: 20px; 34 | margin-bottom: 0px; 35 | } 36 | .dropdown-toggle { 37 | color: #ffffff; 38 | } 39 | .navbar-link { 40 | color: #ffffff; 41 | } 42 | nav.navbar { 43 | background: #008080; 44 | } 45 | .row1 { 46 | margin-top: 20px; 47 | } 48 | .navbar .navbar-nav>li { 49 | font-size: 16px; 50 | } 51 | -------------------------------------------------------------------------------- /docs/site_libs/highlightjs-9.12.0/default.css: -------------------------------------------------------------------------------- 1 | .hljs-literal { 2 | color: #990073; 3 | } 4 | 5 | .hljs-number { 6 | color: #099; 7 | } 8 | 9 | .hljs-comment { 10 | color: #998; 11 | font-style: italic; 12 | } 13 | 14 | .hljs-keyword { 15 | color: #900; 16 | font-weight: bold; 17 | } 18 | 19 | .hljs-string { 20 | color: #d14; 21 | } 22 | -------------------------------------------------------------------------------- /docs/site_libs/highlightjs-9.12.0/textmate.css: -------------------------------------------------------------------------------- 1 | .hljs-literal { 2 | color: rgb(88, 72, 246); 3 | } 4 | 5 | .hljs-number { 6 | color: rgb(0, 0, 205); 7 | } 8 | 9 | .hljs-comment { 10 | color: rgb(76, 136, 107); 11 | } 12 | 13 | .hljs-keyword { 14 | color: rgb(0, 0, 255); 15 | } 16 | 17 | .hljs-string { 18 | color: rgb(3, 106, 7); 19 | } 20 | -------------------------------------------------------------------------------- /docs/site_libs/navigation-1.1/codefolding.js: -------------------------------------------------------------------------------- 1 | 2 | window.initializeCodeFolding = function(show) { 3 | 4 | // handlers for show-all and hide all 5 | $("#rmd-show-all-code").click(function() { 6 | $('div.r-code-collapse').each(function() { 7 | $(this).collapse('show'); 8 | }); 9 | }); 10 | $("#rmd-hide-all-code").click(function() { 11 | $('div.r-code-collapse').each(function() { 12 | $(this).collapse('hide'); 13 | }); 14 | }); 15 | 16 | // index for unique code element ids 17 | var currentIndex = 1; 18 | 19 | // select all R code blocks 20 | var rCodeBlocks = $('pre.r, pre.python, pre.bash, pre.sql, pre.cpp, pre.stan, pre.julia, pre.foldable'); 21 | rCodeBlocks.each(function() { 22 | 23 | // create a collapsable div to wrap the code in 24 | var div = $('
'); 25 | show = (show || $(this).hasClass('fold-show')) && !$(this).hasClass('fold-hide'); 26 | if (show) div.addClass('in'); 27 | var id = 'rcode-643E0F36' + currentIndex++; 28 | div.attr('id', id); 29 | $(this).before(div); 30 | $(this).detach().appendTo(div); 31 | 32 | // add a show code button right above 33 | var showCodeText = $('' + (show ? 'Hide' : 'Code') + ''); 34 | var showCodeButton = $(''); 35 | showCodeButton.append(showCodeText); 36 | showCodeButton 37 | .attr('data-toggle', 'collapse') 38 | .attr('data-target', '#' + id) 39 | .attr('aria-expanded', show) 40 | .attr('aria-controls', id); 41 | 42 | var buttonRow = $('
'); 43 | var buttonCol = $('
'); 44 | 45 | buttonCol.append(showCodeButton); 46 | buttonRow.append(buttonCol); 47 | 48 | div.before(buttonRow); 49 | 50 | // update state of button on show/hide 51 | div.on('hidden.bs.collapse', function () { 52 | showCodeText.text('Code'); 53 | }); 54 | div.on('show.bs.collapse', function () { 55 | showCodeText.text('Hide'); 56 | }); 57 | }); 58 | 59 | } 60 | -------------------------------------------------------------------------------- /docs/site_libs/navigation-1.1/sourceembed.js: -------------------------------------------------------------------------------- 1 | 2 | window.initializeSourceEmbed = function(filename) { 3 | $("#rmd-download-source").click(function() { 4 | var src = $("#rmd-source-code").html(); 5 | var a = document.createElement('a'); 6 | a.href = "data:text/x-r-markdown;base64," + src; 7 | a.download = filename; 8 | document.body.appendChild(a); 9 | a.click(); 10 | document.body.removeChild(a); 11 | }); 12 | }; 13 | -------------------------------------------------------------------------------- /docs/site_libs/tocify-1.9.1/jquery.tocify.css: -------------------------------------------------------------------------------- 1 | /* 2 | * jquery.tocify.css 1.9.1 3 | * Author: @gregfranko 4 | */ 5 | 6 | /* The Table of Contents container element */ 7 | .tocify { 8 | width: 20%; 9 | max-height: 90%; 10 | overflow: auto; 11 | margin-left: 2%; 12 | position: fixed; 13 | border: 1px solid #ccc; 14 | border-radius: 6px; 15 | } 16 | 17 | /* The Table of Contents is composed of multiple nested unordered lists. These styles remove the default styling of an unordered list because it is ugly. */ 18 | .tocify ul, .tocify li { 19 | list-style: none; 20 | margin: 0; 21 | padding: 0; 22 | border: none; 23 | line-height: 30px; 24 | } 25 | 26 | /* Top level header elements */ 27 | .tocify-header { 28 | text-indent: 10px; 29 | } 30 | 31 | /* Top level subheader elements. These are the first nested items underneath a header element. */ 32 | .tocify-subheader { 33 | text-indent: 20px; 34 | display: none; 35 | } 36 | 37 | /* Makes the font smaller for all subheader elements. */ 38 | .tocify-subheader li { 39 | font-size: 12px; 40 | } 41 | 42 | /* Further indents second level subheader elements. */ 43 | .tocify-subheader .tocify-subheader { 44 | text-indent: 30px; 45 | } 46 | .tocify-subheader .tocify-subheader .tocify-subheader { 47 | text-indent: 40px; 48 | } 49 | .tocify-subheader .tocify-subheader .tocify-subheader .tocify-subheader { 50 | text-indent: 50px; 51 | } 52 | .tocify-subheader .tocify-subheader .tocify-subheader .tocify-subheader .tocify-subheader { 53 | text-indent: 60px; 54 | } 55 | 56 | /* Twitter Bootstrap Override Style */ 57 | .tocify .tocify-item > a, .tocify .nav-list .nav-header { 58 | margin: 0px; 59 | } 60 | 61 | /* Twitter Bootstrap Override Styles */ 62 | .tocify .tocify-item a, .tocify .list-group-item { 63 | padding: 5px; 64 | } 65 | 66 | .tocify .nav-pills > li { 67 | float: none; 68 | } 69 | 70 | /* We don't override the bootstrap colors because this gives us the 71 | wrong selection colors when using bootstrap themes 72 | 73 | .tocify .list-group-item:hover, .tocify .list-group-item:focus { 74 | background-color: #f5f5f5; 75 | } 76 | 77 | .tocify .list-group-item.active:hover, .tocify .list-group-item.active:focus { 78 | background-color: #428bca; 79 | } 80 | */ 81 | 82 | /* End Twitter Bootstrap Override Styles */ 83 | --------------------------------------------------------------------------------