I am trying to do the Panel OLS Regression (which is from linearmodels.panel), but when doing the ‘fit’ function it displays the error.
Below is my code.
mod = PanelOLS(dependent = test_df['ln_entry_total'], exog = test_df[['Exist_Cap_bili', 'WX']], weights = test_df[['gdp', 'pop', 'wage', 'ld_indu', 'ld_infr', 'wind', 'tech', 'PM', 'secon_indu', 'third_indu', 'temp', 'regu']], entity_effects = True, time_effects = True)
print(mod)
res = mod.fit(cov_type = "clustered", cluster_entity=True, cluster_time =True)
print(res)
and the result displays:
PanelOLS
Num exog: 2, Constant: False
Entity Effects: True, Time Effects: True, Num Other Effects: 0
---------------------------------------------------------------------------
ValueError Traceback (most recent call last)
~AppDataLocalTempipykernel_259601658320709.py in <module>
7 print(mod)
8
----> 9 res = mod.fit(cov_type = "clustered", cluster_entity=True, cluster_time =True)
10 print(res)
~anaconda3libsite-packageslinearmodelspanelmodel.py in fit(self, use_lsdv, use_lsmr, low_memory, cov_type, debiased, auto_df, count_effects, **cov_config)
1838 x_effects = np.zeros(x.shape)
1839 else:
-> 1840 y, x, ybar, y_effects, x_effects = self._weighted_fast_path(
1841 low_memory=low_memory
1842 )
~anaconda3libsite-packageslinearmodelspanelmodel.py in _weighted_fast_path(self, low_memory)
1631 w = self.weights.values2d
1632 root_w = cast(Float64Array, np.sqrt(w))
-> 1633 wybar = root_w * (w.T @ y_arr / w.sum())
1634
1635 if not self._has_effect:
ValueError: operands could not be broadcast together with shapes (1105,12) (12,1)
I found out the shape should be (1105,12)(1,12) rather than (1105,12)(12,1) to solve this problem, and 12 is the number of weights that I put in PanelOLS as control variables, which produced the error.
I’d like to know how to solve this problem by modify PanelOLS, or it is even absolutely fine to consider other ways to apply control variables as weights.
I really appreciate any help.
Rune is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.