r - 在 R 中打开一个 dta 文件

标签 r stata

我正在尝试打开一个 Stata .dta文件被压缩成 winrar在 R. 这是我的代码:

library(foreign)
setwd("C:/Users/ASUS/Desktop/Data on oil/Oil discovery")
data <- read.dta("oil_discovery")

我得到:
Error in read.dta("oil_discovery") : unable to open file: 'No such file or directory'

我认为我的问题来自我的工作目录的分配,但我不知道如何管理它。

最佳答案

您需要将完整的文件名指定为 read.dta .这包括文件结尾。也就是说,而不是

 data <- read.dta("oil_discovery")

你需要写
 data <- read.dta("oil_discovery.dta")

如果压缩还有其他问题,我想错误信息会有所不同。然而,Error in read.dta("oil_discovery") : unable to open file: 'No such file or directory'非常明确地指出当前的错误是文件oil_discovery没有找到。

检查名称或路径是否导致错误的一个好方法是使用 choose.files() .也就是说,运行以下行:
 data <- read.dta(choose.files())

这将打开一个弹出窗口,您可以在其中手动选择文件。如果这有效,则文件名被错误指定。

关于r - 在 R 中打开一个 dta 文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37392662/

相关文章:

stata - 使用 Google map 在 Stata 中进行地理编码 : Legal or Illegal?

Stata:找不到 Ado 包

regex - 导入名称不同月份的文件

reshape - 在 Stata 中生成行中变量和列中给定变量的分位数的均值表

R语言: If and else statement (loop)

r - 如何在处理日期时手动向 ggplot2 添加中断?

r - 如何创建条形图并显示平均 Y 值

stata - esttab 中的组数(xtmixed 后)

r - 运行for循环后如何保留标题名称

r - 编写每个架构不同的 R 包