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
Machine Learning setupHow can I break down my loaded dataset into training set and test set, and develop random forest on …
Scoring measures using STATAI have dataset that includes items measuring diagnostic criteria for personality disorders. For each…
Comparing predictions and regression fitted values between two regression models with an additional explanatory varaiableDear Statalisters, I am struggling with a task in which I want to investigate how an additional var…
Importing previously imputed data using mi importHello Stata Users, I have been trying to import previously imputed data (m=0, 1,2,…..20) using mi im…
Wrangling panel data - calculating growth rates and cagrI am working with bisnode panel data https://www.bisnodegroup.com/solutio.../company-data/ which has…
Subscribe to:
Post Comments (Atom)
0 Response to Python Integration: Pandas Package Causing Stata to Close
Post a Comment