python - Creating a CSV file from regressions using Statsmodels and Pandas -
i've been creating various regressions using statsmodels. took data, shaped pandas dataframes, , ran several models on data. i'm struggling output of regressions csv file. goal have of "regression data" (ie coefficients, intercepts, standard errors, etc each control/variable, number of observations , few other datapoints) on 1 axis, title of each regression forming other axis.
so far i've tried multiple approaches, 1 looking promising. method has been using
results = foodpricereg(pricechange, righthandvars) regexport = regtocsv(results) return regexport
to turn printed summary csv file. use
for com in commodity: regout = regloop(com) regressions = pd.dataframe(regout) name = 'regressions/' + com[2] saveframe(regressions, name)
to output regressions csv + .dta file each food category.
i've tried both sorting csv files nested lists , converting them dataframes , trying work them. biggest issue i've had csv output rough , challenging work with. it's not organized other pandas dataframes , i've been unable come reasonably simple solution of data in csv sorted if open in excel, each piece of information end in it's own cell.
to clarify, right each cell of final csv output looks like
dep. variable: ,parboiledcoarserice2014, r-squared: , 0.010 model: ,ols , adj. r-squared: , -0.000 method: ,least squares , f-statistic: , 0.9711 , coef , std err , t ,p>|t| , [0.025 , 0.975] intercept , 28.5204, 0.216, 131.855, 0.000, 28.095, 28.945 cash , 4.5696, 0.501, 9.112, 0.000, 3.584, 5.555 food , 4.1321, 0.501, 8.240, 0.000, 3.147, 5.117 foodcash , 4.2496, 0.501, 8.474, 0.000, 3.264, 5.235 cashtraining, 5.2596, 0.675, 7.787, 0.000, 3.933, 6.587 foodtraining, 5.8696, 0.675, 8.691, 0.000, 4.543, 7.197 control , 4.4396, 0.501, 8.853, 0.000, 3.454, 5.425
whereas want each piece of information it's own row, like:
model: parboiledcoarserice2014 ~ treatment dummies r-squared: 0.010 cash coef: 4.5696 cash std err: 0.501
i'm thinking i'm missing fundamental working statsmodels, output of regressions sparsely documented seems essential use out of package.
Comments
Post a Comment