library(foreign)
06.11.2023 Datasets
Different Ways of importing Data
Creating Datasets
from AJR 2001: MIT Website with Data
Load Datasets
<- 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") alldata[[
Merge some of the Datasets
<- merge(alldata[[1]], alldata[[2]])
data head(data)
Search for the Base country sample (should be 64)
nrow(data[which(data[,"baseco"]==1),])
[1] 64
Importing Datasets
Imports
library(foreign)
library(openxlsx)
Warning: Paket 'openxlsx' wurde unter R Version 4.1.2 erstellt
CSV
= read.csv("data/example_datasets/variable_names.csv", sep=";")
df head(df)
Stata .dta
Important: Newer Stata Datasets (>13) use read.dta13()
= read.dta("data/example_datasets/maketable2.dta")
df_stata head(df_stata)
Excel .xlsx
Important: Define Sheet and start rows!
= read.xlsx("data/example_datasets/61111-0002.xlsx", sheet = "data_ed_HA", startRow=1, colNames=T)
df_excel head(df_excel)
ASCII
normal text format
= read.table("data/example_datasets/Per_Capita_GDP_Data_1870-1987.asc", header=T)
df_ascii head(df_ascii)