Estimating with Python

It is relatively easy to do an estimate with a Python script. This is due to the fact that Python works with matrices and such matrices can be used as an input in a estimation procedure. I created an example where a dataset is retrieve from Oracle. Then the dataset is translated into a matrix. Subsequently some columns from that matrix are taken as dependent and independent variables, which are subsequently used as input to an OLS estimation procedure.
The code:

import cx_Oracle
import numpy as np
import statsmodels.api as sm
con = cx_Oracle.connect('scott/bunvegni@van-maanen.com/orcl')
cur = con.cursor()
cur.execute('select * from departments where manager_id is not null')
res = cur.fetchall()
print res
con.close()
A = np.array(res)
y= A[:,0].astype(np.float)
x= A[:,[2,3]].astype(np.float)
lmRegModel = sm.OLS(y,x)
result = lmRegModel.fit()
result.summary()

I use the numpy library to translate the data as retrieved from Oracle into a matrix. I am then able to retrieve one column as the independent variable and 2 columns as independent variables. I explicitly cast them into floats. I am then able to start the estimation process.

Door tom