The first code below runs without problems in python, but when using the same lines in a Stata do-file, a message appears suggesting a Python coding error. Any idea what could cause this problem? (I am using Stata 17 on Windows.)
# PYTHON CODE:
import pandas as pd
df = pd.read_stata('data.dta')
cut_bins = [-5, -4, -3, -2, -1, 0, 1, 2, 3]
df['cut_bins'] = pd.cut(df['v'], bins=cut_bins)
* STATA CODE:
python
import pandas as pd
from sfi import Data
cut_bins = [-5, -4, -3, -2, -1, 0, 1, 2, 3]
df = Data.get('id bin v')
df["cut_bins"] = pd.cut(df['v'], bins=cut_bins)
end
When running the Stata code in a do-file, the following message appears:
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
TypeError: list indices must be integers or slices, not str
This suggests a Python coding error but since the identical lines run in Python without error, it may as well be that there is a problem with Stata.