06.11.2023 Datasets#

Different Ways of importing Data

Creating Datasets#

from AJR 2001: MIT Website with Data

library(foreign)

Load Datasets

alldata <- list()
alldata[[1]] = read.dta("data/datasets/maketable1.dta")
alldata[[2]] = read.dta("data/datasets/maketable2.dta")
alldata[[3]] = read.dta("data/datasets/maketable3.dta")
alldata[[4]] = read.dta("data/datasets/maketable4.dta")
alldata[[5]] = read.dta("data/datasets/maketable5.dta")
alldata[[6]] = read.dta("data/datasets/maketable6.dta")
alldata[[7]] = read.dta("data/datasets/maketable7.dta")
alldata[[8]] = read.dta("data/datasets/maketable8.dta")

Merge some of the Datasets

data <- merge(alldata[[1]], alldata[[2]])
head(data)

Search for the Base country sample (should be 64)

nrow(data[which(data[,"baseco"]==1),])

Importing Datasets#

Imports

library(foreign)
library(openxlsx)

CSV#

df = read.csv("data/example_datasets/variable_names.csv", sep=";")
head(df)

Stata .dta#

Important: Newer Stata Datasets (>13) use read.dta13()

df_stata = read.dta("data/example_datasets/maketable2.dta")
head(df_stata)

Excel .xlsx#

Important: Define Sheet and start rows!

df_excel = read.xlsx("data/example_datasets/61111-0002.xlsx", sheet = "data_ed_HA", startRow=1, colNames=T)
head(df_excel)

ASCII#

normal text format

df_ascii = read.table("data/example_datasets/Per_Capita_GDP_Data_1870-1987.asc", header=T)
head(df_ascii)