# Share of Foreign Born Workers

**URL:** <https://forum.ipums.org/t/share-of-foreign-born-workers/4152>\
**Category:** General\
**Created:** [May 28, 2021, 11:12pm UTC](https://forum.ipums.org/t/share-of-foreign-born-workers/4152 "2021-05-28T23:12:32Z")\
**Posts on this page:** 1\
**Showing post:** 4

<div class="post-metadata">

**Author:** ![Matthew\_Bombyk](https://avatars.discourse-cdn.com/v4/letter/m/34f0e0/32.png) [@Matthew\_Bombyk](https://forum.ipums.org/u/Matthew_Bombyk)\
**Post date:** [June 2, 2021, 10:23pm UTC](https://forum.ipums.org/t/share-of-foreign-born-workers/4152/4 "2021-06-02T22:23:26Z")

</div>

The weights will account for the differing sample densities. In R the most common way to include weights in your analysis is using the [survey](https://cran.r-project.org/web/packages/survey/survey.pdf) package (and its derivative, [srvyr](https://cran.r-project.org/web/packages/srvyr/index.html)). For example this package includes the svymean() function which calculates weighted means. In your case since you’re calculating statistics for a subpopulation, you should use the subset() or svyby() functions to define the subsample.

The proper method for calculating standard errors and confidence intervals in the ACS and ASEC samples is to use [replicate weights](https://usa.ipums.org/usa/repwt.shtml). You’ll need to add the variable REPWTP (same for [USA](https://usa.ipums.org/usa-action/variables/REPWTP#description_section) and [CPS](https://cps.ipums.org/cps-action/variables/repwtp#description_section)) to your extract, and note that this will greatly increase the size of your extract. Example code for using replicate weights in R can be found on [this forum thread](https://forum.ipums.org/t/how-can-i-use-replicate-weights-to-create-standard-errors-in-r/2593/2).

---

_[View the full topic](https://forum.ipums.org/t/share-of-foreign-born-workers/4152)._
