1

这可能很容易,但是在过去几个小时在线查看文档和可能的示例之后,我无法弄清楚。

我有一个大型数据集(电子表格),它被 DO 文件大量清理。然后,在 DO 文件中,我想将清理后的数据的某些变量保存为临时 .csv,运行一些 Python 脚本,生成新的 CSV,然后将该输出附加到清理后的数据中。

如果不清楚,这里是一个例子。

After cleaning my data set (XYZ) goes from variables A to Z with 100 observations. I want to take variables A and D through F and save it as test.csv. I then want to run a python script that takes this data and creates new variables AA to GG. I want to then take that information and append it to the XYZ dataset (making the dataset now go from A to GG with 100 observations) and then be able to run a second part of my DO file for analysis.

我一直在手动执行此操作,这很好,但文件将开始快速更改,这将为我节省大量时间。

4

2 回答 2

1

这行得通吗(假设你可以使用 python

tempfile myfiletemp
save `myfiletemp'
outsheet myfile1.csv
shell python.exe myscript.py
insheet myfile2.csv, clear
append using `myfiletemp'
于 2012-10-22T17:40:30.883 回答
0

在 Stata 中输入“帮助外壳”。您要做的是从 Stata 中脱壳,调用 Python,然后在 Python 脚本完成后让 Stata 恢复您希望它执行的任何操作。

于 2012-10-22T17:38:16.047 回答