I am trying to open a Stata .dta
file which is compressed into winrar
in R. Here are my codes:
library(foreign)
setwd("C:/Users/ASUS/Desktop/Data on oil/Oil discovery")
data <- read.dta("oil_discovery")
and I get :
Error in read.dta("oil_discovery") : unable to open file: 'No such file or directory'
I think that my problem is coming from the assignment of my working directory but I don't know how to manage it.
Double-click on a Stata data file, which is a file whose extension is . dta. Note: The file extension may not be visible, depending on what options you have set in your operating system. Select File > Open... or click on the Open button and navigate to the file.
dta files into R is the readstata13 package, which, despite what the name suggests, can read Stata 13 and Stata 14 files.
If you look at the package listing in the Packages panel, you will find a package called datasets. Simply check the checkbox next to the package name to load the package and gain access to the datasets. You can also click on the package name and RStudio will open a help file describing the datasets in this package.
You need to specify the full file name to read.dta
. This includes the file ending. That is, instead of
data <- read.dta("oil_discovery")
you need to write
data <- read.dta("oil_discovery.dta")
If there is an additional problem with the compression, I would imagine that the error message will be different. However, Error in read.dta("oil_discovery") : unable to open file: 'No such file or directory'
very explicitly points out that the current error is that the file oil_discovery
is not found.
A good way to check if the name or path is causing the error is to use choose.files()
. That is, run the following line:
data <- read.dta(choose.files())
This will open a pop-up window where you can manually select the file. If this works, then the name of the file was misspecified.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With