I was trying to understand how GRETL calculates R^2 for fixed-effects panel-data models as the value it produces is different from Stata and R's plm library.
As far as I have been able to understand, the calculation happens in the function fix_within_stats in the file lib/src/gretl_panel.c as follows (line 1758-9 in the current CVS head, comment in the original):
/* should we modify R^2 in this way? */
fmod->rsq = 1.0 - (fmod->ess / fmod->tss);
Here fmod->ess is the error-sum-of-squared from the regression on the demeaned data but fmod->tss has been overwritten earlier in the function (line 1750) by the TSS from the pooled regression.