Code Monkey home page Code Monkey logo

webuse's Introduction

Import Stata 'webuse' Datasets

This package provides a Stata-style webuse() function for importing named datasets from Stata's online collection.

Package Installation

This package can be installed from R using install.packages("webuse") or from GitHub using remotes:

if(!require("remotes")){
    install.packages("remotes")
}
remotes::install_github("leeper/webuse")

Build Status CRAN Version Downloads

Code Examples

Functionality is simple. Load webuse and then access any online Stata dataset using the webuse() function. This will assign the named dataset from Stata 15 to the .GlobalEnv:

library("webuse")
webuse("auto")
head(auto)

As an option, you can specify the Stata version of the dataset and the environment via version and envir parameters:

library("webuse")
webuse("auto", version = 15, envir = parent.frame())
head(auto)
## # A tibble: 6 x 12
##   make        price   mpg rep78 headroom trunk weight length  turn displacement gear_ratio foreign 
##   <chr>       <dbl> <dbl> <dbl>    <dbl> <dbl>  <dbl>  <dbl> <dbl>        <dbl>      <dbl> <dbl+lb>
## 1 AMC Concord 4099.   22.    3.     2.50   11.  2930.   186.   40.         121.       3.58 0       
## 2 AMC Pacer   4749.   17.    3.     3.00   11.  3350.   173.   40.         258.       2.53 0       
## 3 AMC Spirit  3799.   22.   NA      3.00   12.  2640.   168.   35.         121.       3.08 0       
## 4 Buick Cent~ 4816.   20.    3.     4.50   16.  3250.   196.   40.         196.       2.93 0       
## 5 Buick Elec~ 7827.   15.    4.     4.00   20.  4080.   222.   43.         350.       2.41 0       
## 6 Buick LeSa~ 5788.   18.    3.     4.00   21.  3670.   218.   43.         231.       2.73 0
webuse("uslifeexp")
head(uslifeexp)
## # A tibble: 6 x 10
##    year    le le_male le_female  le_w le_wmale le_wfemale  le_b le_bmale le_bfemale
##   <dbl> <dbl>   <dbl>     <dbl> <dbl>    <dbl>      <dbl> <dbl>    <dbl>      <dbl>
## 1 1900.  47.3    46.3      48.3  47.6     46.6       48.7  33.0     32.5       33.5
## 2 1901.  49.1    47.6      50.6  49.4     48.0       51.0  33.7     32.2       35.3
## 3 1902.  51.5    49.8      53.4  51.9     50.2       53.8  34.6     32.9       36.4
## 4 1903.  50.5    49.1      52.0  50.9     49.5       52.5  33.1     31.7       34.6
## 5 1904.  47.6    46.2      49.1  48.0     46.6       49.5  30.8     29.1       32.7
## 6 1905.  48.7    47.3      50.2  49.1     47.6       50.6  31.3     29.6       33.1

The webuselist object contains a list of "core" Stata datasets:

str(webuselist)
## List of 26
##  $ auto      : chr "1978 Automobile Data"
##  $ auto2     : chr "1978 Automobile Data"
##  $ autornd   : chr "Subset of 1978 Automobile Data"
##  $ bplong    : chr "fictional blood pressure data"
##  $ bpwide    : chr "fictional blood pressure data"
##  $ cancer    : chr "Patient Survival in Drug Trial"
##  $ census    : chr "1980 Census data by state"
##  $ citytemp  : chr "City Temperature Data"
##  $ citytemp4 : chr "City Temperature Data"
##  $ educ99gdp : chr "Education and GDP"
##  $ gnp96     : chr "U.S. GNP, 1967-2002"
##  $ lifeexp   : chr "Life expectancy, 1998"
##  $ network1  : chr "fictional network diagram data"
##  $ network1a : chr "fictional network diagram data"
##  $ nlsw88    : chr "U.S. National Longitudinal Study of Young Women (NLSW, 1988 extract)"
##  $ nlswide1  : chr "U.S. National Longitudinal Study of Young Women (NLSW, 1988 extract)"
##  $ pop2000   : chr "U.S. Census, 2000, extract"
##  $ sandstone : chr "Subsea elevation of Lamont sandstone in an area of Ohio"
##  $ sp500     : chr "S&P 500"
##  $ surface   : chr "NOAA Sea Surface Temperature"
##  $ tsline1   : chr "simulated time-series data"
##  $ tsline2   : chr "fictional data on calories consumed"
##  $ uslifeexp : chr "U.S. life expectancy, 1900-1999"
##  $ uslifeexp2: chr "U.S. life expectancy, 1900-1940"
##  $ voter     : chr "1992 presidential voter data"
##  $ xtline1   : chr "fictional data on calories consumed"

webuse's People

Contributors

hadley avatar jodibeggs avatar leeper avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

webuse's Issues

Inconsistency between Usage and Arguments

This could not be more trivial, but in the Arguments section it says that the version is "An integer indicating the version of Stata for which to retrieve the named dataset. Default is version 14 (current as of June, 2015)." In the Usage, the default is indicated as v 15.

Small error in "CITATION"

Hi Tom!

There's a small error in the first line of the CITATION file:

citHeader("To cite package 'arco' in publications use:")

I'm pretty sure it's because you had your older package in mind :)

Best,
Danilo

webuse and latest datasets

Apologies for bombarding you with issues, but for me the readme example:

library("webuse")
webuse("auto")

Produces:

Error in df_parse_dta_raw(spec, encoding) : 
  Failed to parse file: This version of the file format is not supported.

Setting version doesn't help either. webuse("auto", version=12) produces same error.

Rio vs haven

Using rio adds a pretty heavy dep tree. Any reason not to just use haven directly?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.