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
Dynamic panel model with lagged effects of x on YI have dynamic panel data (countries=27 and t=21) with dependent variable (Y) and the independent va…
Issue with UK census data shape filesHi, I have over 200K items with individual latitude longitude coordinates, most in the UK. Ultimatel…
Dropping variables by number of non-missing valuesWorking with Stata 15 on Mac OS Sierra, I'm attempting to work with Oklahoma voting data (available …
Create new variable based small value among two existing variablesHello, I would like to generate new variable by choosing a small value between two existing variabl…
Biprobit postestimation predicted probability table using esttab commandHi, I am using biprobit command and then trying to estimate joint probabilities. However, when I tr…
Subscribe to:
Post Comments (Atom)
0 Response to Python Integration: Pandas Package Causing Stata to Close
Post a Comment