After setting my python_userpath and python_exec, attempting to execute the following lines from a do file causes Stata to exit immediately:
python
import os
import time
import csv
import datetime
import pandas as pd
import numpy as np
df_resp = pd.read_stata("responses.dta")
df_resp
end
I am using Stata 16 on a Mac (Catalina OS: 10.15.7). Following Chuck Huber's blog posts, I have had some success in using Python from within Stata. I have a recent version of Anaconda installed, and Stata is recently updated.
However, when I try to load a Stata dataset into Python using the Pandas command, "read_stata," Stata immediately exits. There is no error warning or message, only immediate exit from Stata.
Initially, this same immediate exit behavior occurred whenever I typed "python which pandas". Another Stata user described the same behavior in the comments of the previously linked blog post. By re-installing Pandas, I was able to run "python which pandas" successfully.
Strangely, the do file above ran successfully once and returned the expected result. I cannot determine what was different in that lone successful instance. The entire do file is:
*prepare python
set python_exec "~/opt/anaconda3/bin/python3"
set python_userpath "~/opt/anaconda3/lib/python3.8/site-packages"
python query
*python modules
python which os
python which time
python which csv
python which datetime
python which pandas
python which numpy
*load data into python using pandas (read_stata)
python
import os
import time
import csv
import datetime
import pandas as pd
import numpy as np
df_resp = pd.read_stata("responses.dta")
df_resp
end
Any suggestions?
Related Posts with Python Integration: Pandas Package Causing Stata to Close
Gini coefficientHello Excuse ، I have the income data and the number of people in each household and the weight of h…
How to extract rar files with stata?How to extract rar files with stata?For example,I can use unzipfile to extract the zip file.What abo…
Instrumenting a Lagged Dependent VariableHello all, I was curious if someone code help me with Stata code in instrumenting a lagged dependen…
create individual identifiers numbered from 0 upwardsHi, I need to create a new variable "ID" from a existing variable "Value", i have been trying with …
How to extract rar files with stata?How to extract rar files with stata?For example,I can use unzipfile to extract the zip file.What* ab…
Subscribe to:
Post Comments (Atom)
0 Response to Python Integration: Pandas Package Causing Stata to Close
Post a Comment