Skip to content

Commit

Permalink
new post: data-dictionary
Browse files Browse the repository at this point in the history
  • Loading branch information
matt-gunther committed Dec 9, 2022
1 parent 6a44bc3 commit ffc3434
Show file tree
Hide file tree
Showing 123 changed files with 176,564 additions and 26 deletions.
68 changes: 68 additions & 0 deletions _posts/2022-12-09-data-dictionary/codebook.Rmd
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
---
cap-location: margin
css: 'custom.css'
output:
pagedown::html_paged:
toc: true
self_contained: false
toc-title: 'IPUMS PMA Codebook: <br>Pregnancy Termination Variables'
lot: false
lof: false
paged-footnotes: true
---

```{r, echo=FALSE,results='hide', message=FALSE}
source(here::here("r/utilities.r"))
set_postpath("2022-12-09-data-dictionary")
library(ipumsr)
library(tidyverse)
library(gtsummary)
library(gt)
dat <- read_ipums_micro(
ddi = "data/pma_00180.xml",
data = "data/pma_00180.dat.gz"
)
```


```{r, echo = FALSE, results='asis'}
dd <- dat %>% ipums_var_info() %>% slice(-c(1:12))
dd$tbl <- dd$var_name %>%
map(
~if(dat[[.x]] %>% is.labelled){
dat %>%
select(!!.x) %>%
mutate(across(where(is.labelled), ~.x %>% as_factor %>% fct_drop)) %>%
tbl_summary() %>%
modify_footnote(update = list(stat_0 ~ NA)) %>%
bold_labels() %>%
as_gt() %>%
tab_options(
column_labels.hidden = TRUE,
table.font.names = "cabrito_sans_norm_regular",
table.width = gt::pct(100),
table.font.size = ".8em"
)
}
)
dd %>%
pwalk(function(...){
text <- list(...)
text$var_name %>%
paste("#", ., "{.unnumbered} \n\n") %>%
paste(text$var_desc, "\n\n") %>%
cat()
if(is.null(text$tbl)){
cat("*Table omitted for space constraints*\n\n")
} else {
text$tbl %>% as_raw_html() %>% cat()
}
})
```


6,334 changes: 6,334 additions & 0 deletions _posts/2022-12-09-data-dictionary/codebook.html

Large diffs are not rendered by default.

Binary file added _posts/2022-12-09-data-dictionary/codebook.pdf
Binary file not shown.
63 changes: 63 additions & 0 deletions _posts/2022-12-09-data-dictionary/codebook2.Rmd
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
---
cap-location: margin
css: 'custom.css'
output:
pagedown::html_paged:
toc: true
self_contained: false
toc-title: 'IPUMS PMA Codebook: <br>Pregnancy Termination Variables'
lot: false
lof: false
paged-footnotes: true
---

```{r, echo=FALSE,results='hide', message=FALSE}
source(here::here("r/utilities.r"))
set_postpath("2022-12-09-data-dictionary")
library(ipumsr)
library(tidyverse)
library(gtsummary)
library(gt)
dat <- read_ipums_micro(
ddi = "data/pma_00180.xml",
data = "data/pma_00180.dat.gz"
)
```


```{r, echo = FALSE, results='asis'}
dd <- read_rds("data/dd.rds.gz") %>%
slice(-c(1:12)) %>%
mutate(
var_name = var_name %>%
paste("#", ., "{.unnumbered}"),
comp = comp %>%
str_replace("Comparability", "#### Comparability {.unnumbered}\n"),
avail = avail %>%
str_replace_all("\n", "\n - ") %>%
str_replace("Availability", "#### Availability {.unnumbered}\n"),
universe = universe %>%
str_replace_all("\n", "\n - ") %>%
str_replace("Universe", "#### Universe {.unnumbered}\n")
)
dd %>%
ungroup() %>%
pwalk(function(...){
text <- list(...)
cat(text$var_name, "\n\n")
cat(text$var_desc, "\n\n")
cat(text$comp, "\n\n")
cat(text$avail, "\n\n")
cat(text$universe, "\n\n")
cat("#### Results {.unnumbered} \n\n")
if(is.null(text$tbl)){
cat("*Table omitted for space constraints*\n\n")
} else {
text$tbl %>% as_raw_html() %>% cat()
}
})
```

8,044 changes: 8,044 additions & 0 deletions _posts/2022-12-09-data-dictionary/codebook2.html

Large diffs are not rendered by default.

Binary file added _posts/2022-12-09-data-dictionary/codebook2.pdf
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
@import 'https://fonts.googleapis.com/css?family=Old+Standard+TT';

body {
font-family: 'Old Standard TT', Palatino, "Palatino Linotype", "Palatino LT STD", Georgia, 'source-han-serif-sc', 'Source Han Serif SC', 'Source Han Serif CN', 'Source Han Serif TC', 'Source Han Serif TW', 'Source Han Serif', 'Songti SC', 'Microsoft YaHei', serif;
}
blockquote {
font-family: 'Old Standard TT', Palatino, "Palatino Linotype", "Palatino LT STD", Georgia, 'STKaiti', 'KaiTi', '楷体', 'SimKai', 'DFKai-SB', 'NSimSun', serif;
}
code {
font-family: Consolas, Courier, "Courier New", 'STKaiti', 'KaiTi', 'SimKai', monospace;
}
pre, code {
font-size: .95em;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,170 @@
/* page size */
@page {
size: 6in 9in; /* var(--pagedjs-width) doesn't work in browser when printing */
}
@page :blank {

}

/* store some string variables */
.shorttitle1 {
string-set: h1-text content(text);
}

.shorttitle2 {
string-set: h2-text content(text);
}

/* left page */
.running-h1-title {
position: running(runningH1Title);
width: var(--running-title-width);
text-overflow: ellipsis;
overflow: hidden;
}
.running-h1-title:before {
content: string(h1-text);
}

@page chapter:left {
@top-left {
content: counter(page);
}
@top-right {
content: element(runningH1Title);
white-space: nowrap !important;
}
}

/* right page */
.running-h2-title {
position: running(runningH2Title);
width: var(--running-title-width);
text-overflow: ellipsis;
overflow: hidden;
}
.running-h2-title:before {
/* We would want to write: */
/* content: string(h2-text, start); */
/* However, this is yet unsupported by Paged.js, see https://gitlab.coko.foundation/pagedjs/pagedjs/-/issues/38 */
content: string(h2-text);
}
@page chapter:right {
@top-right {
content: counter(page);
}
@top-left {
content: element(runningH2Title);
white-space: nowrap !important;
}
}

/* New chapter page */
@page chapter:first {
@top-left {
content: none;
}
@top-right {
content: none;
}
@bottom-right {
content: counter(page);
}
}
@page :first {
@top-left {
content: none;
}
@top-right {
content: none;
}
@bottom-right {
content: none !important;
}
background-image: var(--front-cover);
background-position: center;
background-size: contain;
background-repeat: no-repeat;
}

/* Front cover */
.front-cover {
break-after: recto;
}

/* Front page or title page */
.front-page {
counter-reset: page 1;
}

/* Front matter*/
@page frontmatter:left {
@top-left {
content: counter(page, lower-roman);
}
@top-right {
content: element(runningH1Title);
white-space: nowrap !important;
}
}
@page frontmatter:right {
@top-right {
content: counter(page, lower-roman);
}
@top-left {
content: element(runningH1Title);
white-space: nowrap !important;
}
}
@page frontmatter:first {
@top-left {
content: none;
}
@top-right {
content: none;
}
@bottom-right {
content: counter(page, lower-roman);
}
}

/* last page or back cover */
.back-cover {
break-before: verso;
}
.pagedjs_page:nth-last-of-type(1) {
background-image: var(--back-cover);
background-position: center;
background-size: contain;
background-repeat: no-repeat;
}

/* page breaks; aka CSS fragmentation */
.level1 {
break-before: recto;
page: chapter;
}
.front-matter-container .level1 {
page: frontmatter;
}
.section > h1, .section > h2, .section > h3, .section > h4, .section > h5, .section > h6 {
break-after: avoid;
}
.footenotes {
break-before: always;
break-after: always;
}
.figure {
break-inside: avoid;
}

/* reset page numbering for main content */
.main .level1:first-child h1 {
counter-reset: page 1;
}

/* do not break captions */
caption {
break-inside: avoid;
break-after: avoid;
}
Loading

0 comments on commit ffc3434

Please sign in to comment.