Skip to content

Commit

Permalink
acs 2022
Browse files Browse the repository at this point in the history
  • Loading branch information
ajdamico committed Jan 30, 2024
1 parent b8dbefc commit 5a474a7
Show file tree
Hide file tree
Showing 10 changed files with 46 additions and 49 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
# You can find the book at http://asdfree.com/
american-community-survey-acs: <p><a href="https://github.com/asdfree/acs/actions"><img src="https://github.com/asdfree/acs/actions/workflows/r.yml/badge.svg" alt="Github Actions Badge"></a></p>
american-housing-survey-ahs: <p><a href="https://github.com/asdfree/ahs/actions"><img src="https://github.com/asdfree/ahs/actions/workflows/r.yml/badge.svg" alt="Github Actions Badge"></a></p>
american-national-election-studies-anes: <p><img src='https://img.shields.io/badge/tested%20on%20my%20laptop:-2024 01 24-brightgreen' alt='Local Testing Badge'></p>
american-national-election-studies-anes: <p><img src='https://img.shields.io/badge/tested%20on%20my%20laptop:-2024 01 30-brightgreen' alt='Local Testing Badge'></p>
american-time-use-survey-atus: <p><a href="https://github.com/asdfree/atus/actions"><img src="https://github.com/asdfree/atus/actions/workflows/r.yml/badge.svg" alt="Github Actions Badge"></a></p>
area-health-resources-files-ahrf: <p><a href="https://github.com/asdfree/ahrf/actions"><img src="https://github.com/asdfree/ahrf/actions/workflows/r.yml/badge.svg" alt="Github Actions Badge"></a></p>
behavioral-risk-factor-surveillance-system-brfss: <p><a href="https://github.com/asdfree/brfss/actions"><img src="https://github.com/asdfree/brfss/actions/workflows/r.yml/badge.svg" alt="Github Actions Badge"></a></p>
census-of-governments-cog: <p><a href="https://github.com/asdfree/cog/actions"><img src="https://github.com/asdfree/cog/actions/workflows/r.yml/badge.svg" alt="Github Actions Badge"></a></p>
consumer-expenditure-survey-ces: <p><a href="https://github.com/asdfree/ces/actions"><img src="https://github.com/asdfree/ces/actions/workflows/r.yml/badge.svg" alt="Github Actions Badge"></a></p>
current-population-survey-cps: <p><a href="https://github.com/asdfree/cps/actions"><img src="https://github.com/asdfree/cps/actions/workflows/r.yml/badge.svg" alt="Github Actions Badge"></a></p>
european-social-survey-ess: <p><img src='https://img.shields.io/badge/tested%20on%20my%20laptop:-2024 01 24-brightgreen' alt='Local Testing Badge'></p>
european-social-survey-ess: <p><img src='https://img.shields.io/badge/tested%20on%20my%20laptop:-2024 01 30-brightgreen' alt='Local Testing Badge'></p>
exame-nacional-de-desempenho-de-estudantes-enade: <p><a href="https://github.com/asdfree/enade/actions"><img src="https://github.com/asdfree/enade/actions/workflows/r.yml/badge.svg" alt="Github Actions Badge"></a></p>
exame-nacional-do-ensino-medio-enem: <p><a href="https://github.com/asdfree/enem/actions"><img src="https://github.com/asdfree/enem/actions/workflows/r.yml/badge.svg" alt="Github Actions Badge"></a></p>
fda-adverse-event-reporting-system-faers: <p><a href="https://github.com/asdfree/faers/actions"><img src="https://github.com/asdfree/faers/actions/workflows/r.yml/badge.svg" alt="Github Actions Badge"></a></p>
Expand Down
26 changes: 12 additions & 14 deletions acs.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -32,16 +32,15 @@ Please skim before you begin:

## Download, Import, Preparation {-}

Download and import the Alabama household file:
Choose either the entire **United States** with `sas_hus.zip`, or use a state's abbreviation like `sas_hal.zip` for **Alabama** or `sas_hak.zip` for **Alaska**. This imports the **Alabama** household file:

(switch `sas_hal` to `sas_hak` for Alaska or `sas_hus` for the entire country)
```{r eval = FALSE , results = "hide" }
library(haven)
tf_household <- tempfile()
this_url_household <-
"https://www2.census.gov/programs-surveys/acs/data/pums/2021/1-Year/sas_hal.zip"
"https://www2.census.gov/programs-surveys/acs/data/pums/2022/1-Year/sas_hal.zip"
download.file( this_url_household , tf_household , mode = 'wb' )
Expand All @@ -55,14 +54,13 @@ acs_df_household <- read_sas( acs_sas_household )
names( acs_df_household ) <- tolower( names( acs_df_household ) )
```

Download and import the Alabama person file:
Choose either the entire **United States** with `sas_pus.zip`, or use a state's abbreviation like `sas_pal.zip` for **Alabama** or `sas_pak.zip` for **Alaska**. This imports the **Alabama** person file:

(switch `sas_pal` to `sas_pak` for Alaska or `sas_pus` for the entire country)
```{r eval = FALSE , results = "hide" }
tf_person <- tempfile()
this_url_person <-
"https://www2.census.gov/programs-surveys/acs/data/pums/2021/1-Year/sas_pal.zip"
"https://www2.census.gov/programs-surveys/acs/data/pums/2022/1-Year/sas_pal.zip"
download.file( this_url_person , tf_person , mode = 'wb' )
Expand Down Expand Up @@ -346,28 +344,28 @@ summary( glm_result )

## Replication Example {-}

This example matches statistics, standard errors, and margin of errors from the [2021 PUMS tallies](https://www2.census.gov/programs-surveys/acs/tech_docs/pums/estimates/pums_estimates_21.csv):
This matches statistics, standard errors, and margin of errors from Alabama's [2022 PUMS tallies](https://www2.census.gov/programs-surveys/acs/tech_docs/pums/estimates/pums_estimates_22.csv):

Match the sum of the weights:

```{r eval = FALSE , results = "hide" }
stopifnot( round( coef( svytotal( ~ one , acs_design ) ) , 0 ) == 5039877 )
stopifnot( round( coef( svytotal( ~ one , acs_design ) ) , 0 ) == 5074296 )
```

Compute the population by age:

```{r eval = FALSE , results = "hide" }
pums_estimate <-
c(288139L, 299245L, 336727L, 334606L, 327102L, 635004L, 641405L,
615709L, 335431L, 341926L, 538367L, 265742L, 80474L)
c(277094L, 316627L, 319132L, 336759L, 350132L, 651975L, 633907L,
616899L, 317765L, 341937L, 543576L, 284790L, 83703L)
pums_standard_error <-
c(2727L, 5368L, 6067L, 4082L, 4485L, 5716L, 4420L, 3706L, 4836L,
5100L, 2158L, 3363L, 3186L)
c(2624L, 5197L, 5002L, 4112L, 3626L, 5047L, 4559L, 4538L, 5849L,
5731L, 2061L, 3527L, 2896L)
pums_margin_of_error <-
c(4486L, 8830L, 9981L, 6715L, 7378L, 9402L, 7271L, 6096L, 7956L,
8389L, 3550L, 5532L, 5240L)
c(4317L, 8550L, 8229L, 6764L, 5964L, 8302L, 7499L, 7465L, 9622L,
9427L, 3390L, 5801L, 4765L)
results <-
svytotal(
Expand Down
Binary file not shown.
Binary file not shown.
26 changes: 12 additions & 14 deletions docs/american-community-survey-acs.html
Original file line number Diff line number Diff line change
Expand Up @@ -1013,14 +1013,13 @@ <h1>American Community Survey (ACS)<a href="american-community-survey-acs.html#a
<hr />
<div id="download-import-preparation-1" class="section level2 unnumbered hasAnchor">
<h2>Download, Import, Preparation<a href="american-community-survey-acs.html#download-import-preparation-1" class="anchor-section" aria-label="Anchor link to header"></a></h2>
<p>Download and import the Alabama household file:</p>
<p>(switch <code>sas_hal</code> to <code>sas_hak</code> for Alaska or <code>sas_hus</code> for the entire country)</p>
<p>Choose either the entire <strong>United States</strong> with <code>sas_hus.zip</code>, or use a state’s abbreviation like <code>sas_hal.zip</code> for <strong>Alabama</strong> or <code>sas_hak.zip</code> for <strong>Alaska</strong>. This imports the <strong>Alabama</strong> household file:</p>
<div class="sourceCode" id="cb21"><pre class="sourceCode r"><code class="sourceCode r"><span id="cb21-1"><a href="american-community-survey-acs.html#cb21-1" tabindex="-1"></a><span class="fu">library</span>(haven)</span>
<span id="cb21-2"><a href="american-community-survey-acs.html#cb21-2" tabindex="-1"></a></span>
<span id="cb21-3"><a href="american-community-survey-acs.html#cb21-3" tabindex="-1"></a>tf_household <span class="ot">&lt;-</span> <span class="fu">tempfile</span>()</span>
<span id="cb21-4"><a href="american-community-survey-acs.html#cb21-4" tabindex="-1"></a></span>
<span id="cb21-5"><a href="american-community-survey-acs.html#cb21-5" tabindex="-1"></a>this_url_household <span class="ot">&lt;-</span></span>
<span id="cb21-6"><a href="american-community-survey-acs.html#cb21-6" tabindex="-1"></a> <span class="st">&quot;https://www2.census.gov/programs-surveys/acs/data/pums/2021/1-Year/sas_hal.zip&quot;</span></span>
<span id="cb21-6"><a href="american-community-survey-acs.html#cb21-6" tabindex="-1"></a> <span class="st">&quot;https://www2.census.gov/programs-surveys/acs/data/pums/2022/1-Year/sas_hal.zip&quot;</span></span>
<span id="cb21-7"><a href="american-community-survey-acs.html#cb21-7" tabindex="-1"></a></span>
<span id="cb21-8"><a href="american-community-survey-acs.html#cb21-8" tabindex="-1"></a><span class="fu">download.file</span>( this_url_household , tf_household , <span class="at">mode =</span> <span class="st">&#39;wb&#39;</span> )</span>
<span id="cb21-9"><a href="american-community-survey-acs.html#cb21-9" tabindex="-1"></a></span>
Expand All @@ -1032,12 +1031,11 @@ <h2>Download, Import, Preparation<a href="american-community-survey-acs.html#dow
<span id="cb21-15"><a href="american-community-survey-acs.html#cb21-15" tabindex="-1"></a>acs_df_household <span class="ot">&lt;-</span> <span class="fu">read_sas</span>( acs_sas_household )</span>
<span id="cb21-16"><a href="american-community-survey-acs.html#cb21-16" tabindex="-1"></a></span>
<span id="cb21-17"><a href="american-community-survey-acs.html#cb21-17" tabindex="-1"></a><span class="fu">names</span>( acs_df_household ) <span class="ot">&lt;-</span> <span class="fu">tolower</span>( <span class="fu">names</span>( acs_df_household ) )</span></code></pre></div>
<p>Download and import the Alabama person file:</p>
<p>(switch <code>sas_pal</code> to <code>sas_pak</code> for Alaska or <code>sas_pus</code> for the entire country)</p>
<p>Choose either the entire <strong>United States</strong> with <code>sas_pus.zip</code>, or use a state’s abbreviation like <code>sas_pal.zip</code> for <strong>Alabama</strong> or <code>sas_pak.zip</code> for <strong>Alaska</strong>. This imports the <strong>Alabama</strong> person file:</p>
<div class="sourceCode" id="cb22"><pre class="sourceCode r"><code class="sourceCode r"><span id="cb22-1"><a href="american-community-survey-acs.html#cb22-1" tabindex="-1"></a>tf_person <span class="ot">&lt;-</span> <span class="fu">tempfile</span>()</span>
<span id="cb22-2"><a href="american-community-survey-acs.html#cb22-2" tabindex="-1"></a></span>
<span id="cb22-3"><a href="american-community-survey-acs.html#cb22-3" tabindex="-1"></a>this_url_person <span class="ot">&lt;-</span></span>
<span id="cb22-4"><a href="american-community-survey-acs.html#cb22-4" tabindex="-1"></a> <span class="st">&quot;https://www2.census.gov/programs-surveys/acs/data/pums/2021/1-Year/sas_pal.zip&quot;</span></span>
<span id="cb22-4"><a href="american-community-survey-acs.html#cb22-4" tabindex="-1"></a> <span class="st">&quot;https://www2.census.gov/programs-surveys/acs/data/pums/2022/1-Year/sas_pal.zip&quot;</span></span>
<span id="cb22-5"><a href="american-community-survey-acs.html#cb22-5" tabindex="-1"></a></span>
<span id="cb22-6"><a href="american-community-survey-acs.html#cb22-6" tabindex="-1"></a><span class="fu">download.file</span>( this_url_person , tf_person , <span class="at">mode =</span> <span class="st">&#39;wb&#39;</span> )</span>
<span id="cb22-7"><a href="american-community-survey-acs.html#cb22-7" tabindex="-1"></a></span>
Expand Down Expand Up @@ -1258,21 +1256,21 @@ <h3>Regression Models and Tests of Association<a href="american-community-survey
</div>
<div id="replication-example" class="section level2 unnumbered hasAnchor">
<h2>Replication Example<a href="american-community-survey-acs.html#replication-example" class="anchor-section" aria-label="Anchor link to header"></a></h2>
<p>This example matches statistics, standard errors, and margin of errors from the <a href="https://www2.census.gov/programs-surveys/acs/tech_docs/pums/estimates/pums_estimates_21.csv">2021 PUMS tallies</a>:</p>
<p>This matches statistics, standard errors, and margin of errors from Alabama’s <a href="https://www2.census.gov/programs-surveys/acs/tech_docs/pums/estimates/pums_estimates_22.csv">2022 PUMS tallies</a>:</p>
<p>Match the sum of the weights:</p>
<div class="sourceCode" id="cb46"><pre class="sourceCode r"><code class="sourceCode r"><span id="cb46-1"><a href="american-community-survey-acs.html#cb46-1" tabindex="-1"></a><span class="fu">stopifnot</span>( <span class="fu">round</span>( <span class="fu">coef</span>( <span class="fu">svytotal</span>( <span class="sc">~</span> one , acs_design ) ) , <span class="dv">0</span> ) <span class="sc">==</span> <span class="dv">5039877</span> )</span></code></pre></div>
<div class="sourceCode" id="cb46"><pre class="sourceCode r"><code class="sourceCode r"><span id="cb46-1"><a href="american-community-survey-acs.html#cb46-1" tabindex="-1"></a><span class="fu">stopifnot</span>( <span class="fu">round</span>( <span class="fu">coef</span>( <span class="fu">svytotal</span>( <span class="sc">~</span> one , acs_design ) ) , <span class="dv">0</span> ) <span class="sc">==</span> <span class="dv">5074296</span> )</span></code></pre></div>
<p>Compute the population by age:</p>
<div class="sourceCode" id="cb47"><pre class="sourceCode r"><code class="sourceCode r"><span id="cb47-1"><a href="american-community-survey-acs.html#cb47-1" tabindex="-1"></a>pums_estimate <span class="ot">&lt;-</span> </span>
<span id="cb47-2"><a href="american-community-survey-acs.html#cb47-2" tabindex="-1"></a> <span class="fu">c</span>(288139L, 299245L, 336727L, 334606L, 327102L, 635004L, 641405L, </span>
<span id="cb47-3"><a href="american-community-survey-acs.html#cb47-3" tabindex="-1"></a> 615709L, 335431L, 341926L, 538367L, 265742L, 80474L)</span>
<span id="cb47-2"><a href="american-community-survey-acs.html#cb47-2" tabindex="-1"></a> <span class="fu">c</span>(277094L, 316627L, 319132L, 336759L, 350132L, 651975L, 633907L, </span>
<span id="cb47-3"><a href="american-community-survey-acs.html#cb47-3" tabindex="-1"></a> 616899L, 317765L, 341937L, 543576L, 284790L, 83703L)</span>
<span id="cb47-4"><a href="american-community-survey-acs.html#cb47-4" tabindex="-1"></a></span>
<span id="cb47-5"><a href="american-community-survey-acs.html#cb47-5" tabindex="-1"></a>pums_standard_error <span class="ot">&lt;-</span> </span>
<span id="cb47-6"><a href="american-community-survey-acs.html#cb47-6" tabindex="-1"></a> <span class="fu">c</span>(2727L, 5368L, 6067L, 4082L, 4485L, 5716L, 4420L, 3706L, 4836L, </span>
<span id="cb47-7"><a href="american-community-survey-acs.html#cb47-7" tabindex="-1"></a> 5100L, 2158L, 3363L, 3186L)</span>
<span id="cb47-6"><a href="american-community-survey-acs.html#cb47-6" tabindex="-1"></a> <span class="fu">c</span>(2624L, 5197L, 5002L, 4112L, 3626L, 5047L, 4559L, 4538L, 5849L, </span>
<span id="cb47-7"><a href="american-community-survey-acs.html#cb47-7" tabindex="-1"></a> 5731L, 2061L, 3527L, 2896L)</span>
<span id="cb47-8"><a href="american-community-survey-acs.html#cb47-8" tabindex="-1"></a></span>
<span id="cb47-9"><a href="american-community-survey-acs.html#cb47-9" tabindex="-1"></a>pums_margin_of_error <span class="ot">&lt;-</span> </span>
<span id="cb47-10"><a href="american-community-survey-acs.html#cb47-10" tabindex="-1"></a> <span class="fu">c</span>(4486L, 8830L, 9981L, 6715L, 7378L, 9402L, 7271L, 6096L, 7956L, </span>
<span id="cb47-11"><a href="american-community-survey-acs.html#cb47-11" tabindex="-1"></a> 8389L, 3550L, 5532L, 5240L)</span>
<span id="cb47-10"><a href="american-community-survey-acs.html#cb47-10" tabindex="-1"></a> <span class="fu">c</span>(4317L, 8550L, 8229L, 6764L, 5964L, 8302L, 7499L, 7465L, 9622L, </span>
<span id="cb47-11"><a href="american-community-survey-acs.html#cb47-11" tabindex="-1"></a> 9427L, 3390L, 5801L, 4765L)</span>
<span id="cb47-12"><a href="american-community-survey-acs.html#cb47-12" tabindex="-1"></a></span>
<span id="cb47-13"><a href="american-community-survey-acs.html#cb47-13" tabindex="-1"></a>results <span class="ot">&lt;-</span></span>
<span id="cb47-14"><a href="american-community-survey-acs.html#cb47-14" tabindex="-1"></a> <span class="fu">svytotal</span>( </span>
Expand Down
2 changes: 1 addition & 1 deletion docs/american-national-election-studies-anes.html
Original file line number Diff line number Diff line change
Expand Up @@ -992,7 +992,7 @@ <h1>
<section class="normal" id="section-">
<div id="american-national-election-studies-anes" class="section level1 unnumbered hasAnchor">
<h1>American National Election Studies (ANES)<a href="american-national-election-studies-anes.html#american-national-election-studies-anes" class="anchor-section" aria-label="Anchor link to header"></a></h1>
<p><img src='https://img.shields.io/badge/tested%20on%20my%20laptop:-2024 01 24-brightgreen' alt='Local Testing Badge'></p>
<p><img src='https://img.shields.io/badge/tested%20on%20my%20laptop:-2024 01 30-brightgreen' alt='Local Testing Badge'></p>
<p>A time series recording belief, public opinion, and political participation back to Dewey vs. Truman.</p>
<ul>
<li><p>Most tables contain one row per sampled eligible voter, varying weights like pre- and post-election.</p></li>
Expand Down
2 changes: 1 addition & 1 deletion docs/european-social-survey-ess.html
Original file line number Diff line number Diff line change
Expand Up @@ -992,7 +992,7 @@ <h1>
<section class="normal" id="section-">
<div id="european-social-survey-ess" class="section level1 unnumbered hasAnchor">
<h1>European Social Survey (ESS)<a href="european-social-survey-ess.html#european-social-survey-ess" class="anchor-section" aria-label="Anchor link to header"></a></h1>
<p><img src='https://img.shields.io/badge/tested%20on%20my%20laptop:-2024 01 24-brightgreen' alt='Local Testing Badge'></p>
<p><img src='https://img.shields.io/badge/tested%20on%20my%20laptop:-2024 01 30-brightgreen' alt='Local Testing Badge'></p>
<p>The barometer of political opinion and behavior across the continent.</p>
<ul>
<li><p>One table per country with one row per sampled respondent.</p></li>
Expand Down
2 changes: 1 addition & 1 deletion docs/search_index.json

Large diffs are not rendered by default.

Loading

0 comments on commit 5a474a7

Please sign in to comment.