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
How to use the egen command and not set missing to zeroHi Statalist, I am using the egen rowlast command to tell me the depression scores for patients in …
Estimation of ATT and ATU for Endogenous Switching Regression ModelDear Statalist Users I am using an endogenous switching regression (ESR) model to conduct my resear…
sigma_u=0 in random effects modelHi all, this is my first post so please let me know if anything can be improved upon! I am conducti…
MESR (multinational endogenous switching regression)Dear Statalist users Would you voluntarily give the Stata command for MESRM and how to calculate th…
Coefplot for coefficient of various estimatesThe following code is supposed to create a graph ( like the attached one here ) but unfortunately, I…
Subscribe to:
Post Comments (Atom)
0 Response to Python Integration: Pandas Package Causing Stata to Close
Post a Comment