Using detailed firm survey data from Spain, We measure the firm total factor productivity (TFP). We find that the distribution of resources is highly correlated with the TFP of the firms, with the exception of the public funding on R&D; motivating a reallocation exercise based on the benchmark efficient economy; the one that reallocates resources to maximize production. Just by reallocating a small share of the total resources in the efficient way -in terms of our model-, particularly the R&D resources that have been funded by public organisms; there are significant reductions in the output loss due to misallocation, suggesting the potential gains of considering the TFP of an establishment when the public sector has to provide funding.