I have a question about Python and Stata in version 16. I checked the documentation and made a small example that basically takes data from Stata, uses this data in Python and writes the results back to Stata. It works but I am not sure if this is "best practise". The code is
Code:
clear all version 16 python: from sfi import Data stata: sysuse auto, clear p = Data.get(var = "price") print(p) for i in range(len(p)): p[i] += 1 Data.addVarFloat("Test") for i in enumerate(p): Data.store("Test", i[0], i[1]) # stata: list price Test end
- When I write the data back to Stata using Data.store, I have to give the observation number where to write. Usually, in Stata observations start with 1. But enumerate, as always in Python, uses index 0 as first index. Still, the result is correct. Why?
- After the second for loop, I have to insert a basically empty line using "#". otherwise I get an error message. This is really strange. What is happening here? If I leave this out and directly insert "stata: ..." there, it does not work and I see:
not found
(0 lines skipped)
0 Response to Python in Stata
Post a Comment