-
Notifications
You must be signed in to change notification settings - Fork 9
Expand file tree
/
Copy pathREADME.Rmd
More file actions
125 lines (91 loc) · 3.74 KB
/
README.Rmd
File metadata and controls
125 lines (91 loc) · 3.74 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
---
title: "readstata13: Read and write the 'Stata' file format with R"
output:
github_document:
fig_width: 4
fig_height: 3.5
---
```{r, echo=FALSE}
knitr::opts_chunk$set(
collapse = TRUE,
comment = "#>",
fig.path = "man/figures/README-")
options(knitr.kable.NA = '')
```
<!-- badges: start -->
[](https://cran.r-project.org/package=readstata13)
[](https://github.com/sjewo/readstata13/actions?workflow=R-CMD-check)
[](https://cran.r-project.org/package=readstata13)
<!-- badges: end -->
Package to read and write all Stata file formats (version 17 and older) into a
R data.frame. The dta file format versions 102 to 121 are supported (including dtas files).
The function ```read.dta``` from the foreign package imports only dta files from
Stata versions <= 12. Due to the different structure and features of dta 117
files, we wrote a new file reader in Rcpp.
Additionally the package supports many features of the Stata dta format like
label sets in different languages (`?set.lang`) or business calendars
(`?as.caldays`).
## Installation
The package is hosted on CRAN.
```{r, eval = FALSE}
install.packages("readstata13")
```
## Usage
```{r, eval = FALSE}
library(readstata13)
dat <- read.dta13("path to file.dta")
save.dta13(dat, file="newfile.dta")
```
## Development Version
To install the current release from github you need the platform specific build
tools. On Windows a current installation of
[Rtools](https://cran.r-project.org/bin/windows/Rtools/) is necessary, while OS X
users need to install
[Xcode](https://apps.apple.com/us/app/xcode/id497799835).
```{r, eval = FALSE}
# install.packages("remotes")
remotes::install_github("sjewo/readstata13", ref="0.11")
```
To install the current development version from github:
```{r, eval = FALSE}
remotes::install_github("sjewo/readstata13", ref="testing")
```
## Changelog and Features
```{r, echo = FALSE}
news <- readLines("NEWS")
news_stop <- which(news == news[grepl("^\\[", news)][2]) - 2
news <- news[1:news_stop]
news_tab <- data.frame(Version = gsub("\\[|\\]", "", news[1]),
Changes = gsub("^- ", "", news[-1]))
news_tab[2:nrow(news_tab), "Version"] <- NA
knitr::kable(news_tab)
```
See [News](NEWS) for the full changelog.
```{r, echo = FALSE}
# create NEWS.MD for pagedown
news <- readLines("NEWS")
newsmd <- gsub("^\\[(.*)\\]", "## readstata13 \\1 \n", news)
cat(newsmd, file ="NEWS.md", sep = "\n")
```
## readstata13 and foreign
Most attributes of the resulting data.frame are largely similar to the data.frames produced by `foreign`.
Since newer Stata files require some additional attributes, the results of `all.equal()` and `identical()` will be `FALSE` for data.frames read by `foreign::read.dta` and `read.dta13()`.
Otherwise, the data.frames produced by both functions are identical.
```{r, eval = FALSE}
library(foreign)
library(readstata13)
# with factors
r12 <- read.dta("http://www.stata-press.com/data/r12/auto.dta")
r13 <- read.dta13("http://www.stata-press.com/data/r13/auto.dta")
all.equal(r12, r13, check.attributes = FALSE)
# without factors
r12 <- read.dta("http://www.stata-press.com/data/r12/auto.dta",
convert.factors = FALSE)
r13 <- read.dta13("http://www.stata-press.com/data/r13/auto.dta",
convert.factors = FALSE)
all.equal(r12, r13, check.attributes = FALSE)
```
## Authors
[Marvin Garbuszus](mailto:jan.garbuszus@ruhr-uni-bochum.de) ([JanMarvin](https://github.com/JanMarvin)) and [Sebastian Jeworutzki](mailto:Sebastian.Jeworutzki@ruhr-uni-bochum.de) ([sjewo](https://github.com/sjewo))
## Licence
GPL2