# Any thoughts on how to apply the codebook formatting to the dataset using R, XML, or SQL?

**URL:** <https://forum.ipums.org/t/any-thoughts-on-how-to-apply-the-codebook-formatting-to-the-dataset-using-r-xml-or-sql/1110>\
**Category:** USA\
**Created:** [November 10, 2015, 7:47pm UTC](https://forum.ipums.org/t/any-thoughts-on-how-to-apply-the-codebook-formatting-to-the-dataset-using-r-xml-or-sql/1110 "2015-11-10T19:47:00Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![christopherrbyrd](https://avatars.discourse-cdn.com/v4/letter/c/5fc32e/32.png) [@christopherrbyrd](https://forum.ipums.org/u/christopherrbyrd)\
**Post date:** [November 10, 2015, 7:47pm UTC](https://forum.ipums.org/t/any-thoughts-on-how-to-apply-the-codebook-formatting-to-the-dataset-using-r-xml-or-sql/1110/1 "2015-11-10T19:47:00Z")

</div>

I don’t have access to SPSS, SAS, or STATA. Would love your input. Note: I’m prepared to write custom code to rebuild the existing basic codebook.

---

<div class="post-metadata">

**Author:** ![Tim\_Moreland](https://avatars.discourse-cdn.com/v4/letter/t/f1d935/32.png) [@Tim\_Moreland](https://forum.ipums.org/u/Tim_Moreland)\
**Post date:** [November 10, 2015, 11:26pm UTC](https://forum.ipums.org/t/any-thoughts-on-how-to-apply-the-codebook-formatting-to-the-dataset-using-r-xml-or-sql/1110/2 "2015-11-10T23:26:00Z")

</div>

Here is one common method for reading formatted IPUMS data into R:

(1) Select “STATA” as your data format on the extract request screen. This will generate a .dta file when you submit your extract.

(2) In R, use the following code with the name of your .dta file:

library(foreign)

df \<- read.dta(“ipums\_file.dta”)

This reads your IPUMS file into a dataframe named “df” with value labels applied. I recommend [this resource](http://www.demog.berkeley.edu/213/TFRI/welcome.pdf) for more information on using IPUMS data in R.

Hope this helps.

---

<div class="post-metadata">

**Author:** ![christopherrbyrd](https://avatars.discourse-cdn.com/v4/letter/c/5fc32e/32.png) [@christopherrbyrd](https://forum.ipums.org/u/christopherrbyrd)\
**Post date:** [November 12, 2015, 4:51pm UTC](https://forum.ipums.org/t/any-thoughts-on-how-to-apply-the-codebook-formatting-to-the-dataset-using-r-xml-or-sql/1110/3 "2015-11-12T16:51:00Z")

</div>

Thanks Tim,

The following update to your answer worked perfect:

install.packages(“readstata13”)

library(readstata13)

df \<- read.dta13(file = “./some\_dir/some\_file.dta”)

---

<div class="post-metadata">

**Author:** ![enystrom](https://avatars.discourse-cdn.com/v4/letter/e/5f9b8f/32.png) [@enystrom](https://forum.ipums.org/u/enystrom)\
**Post date:** [November 13, 2015, 2:41pm UTC](https://forum.ipums.org/t/any-thoughts-on-how-to-apply-the-codebook-formatting-to-the-dataset-using-r-xml-or-sql/1110/4 "2015-11-13T14:41:00Z")

</div>

I wrote a set of Bash/AWK scripts to transform the data and load it into SQLite. Details here: [https://github.com/ericnystrom/napptools](https://github.com/ericnystrom/napptools)
