title: Statsmodels | Display regression results in summary table for data from a for loop
body: <p>I have a panel data/dataframe with 48 countries and each country has 4 sectors, and for each country and sector, 18 years of data exist.</p>
  <p>I am using statsmodels's OLS to run the regression analysis. I want to be able to summarize the results from the analysis into one single table.</p>
  <p>Currently the code, displayed under, prints the results separately for 48 countries. I want to be able to get the results in one table instead of 48.</p>
  <p>`for name, group in df.groupby('country'):
  print(name)</p>
  <pre><code>y=group['elec_rate']
  
  # Model 1: The multiple regression model describes the response as a weighted sum of the predictors:(Elec = beta_0 + beta_1*ED + beta_2*EG,nr ~)
  X0 = group[['Distribution%',
              'Nonrenewable generation%',
              'Policy%',
              'Renewable generation%'                 
              ]]
  
  X0 = sm.add_constant(X0)
  
  reg = sm.OLS(y, X0).fit()
  
  results = summary_col([reg],stars=True,float_format='%0.2f',
                     model_names=['Model 1'],
                     info_dict={'N':lambda x: &quot;{0:d}&quot;.format(int(x.nobs)),
                                'R2':lambda x: &quot;{:.2f}&quot;.format(x.rsquared)})`
  </code></pre>
  <p>Right now I am running the analysis through a for loop to loop through the country as groups. Results are printed out for each individual country. I wonder how to get the summarized data (adj.r^2, significance, const etc.) into one table instead.</p>