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?
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?
Comment