Monday, April 11, 2016

Looping over numbered vars in Stata vs Python

If you want to loop over a list of variables that increment with a number nested inside the variable name, you can:


foreach i of numlist 1(1)34 {
      summ var`i'


for i in range(1,34):
    print(np.mean(eval("x" + str(i))))

No comments:

Post a Comment