Demeaning (two-way) observations manually to perform SEM I have S&P 500 panel data set spanning 10 years. I wish to remove firm and time-fixed effects before performing SEM regression. I want to manually demean all observations (by firm and time) as there would be too many dummies (if I include dummies). I could also use gsem (that allows the inclusion of factor variables) for estimation. But it is recommended to use sem whenever possible.
I am confused if I should do it manually because I have read that manual demeaning and performing regression thereafter leads to underestimation of standard errors.
Could you please suggest any way forward?

If you are doing this approach correctly, you should--must--be using random effects estimators to get sensible answers. This means your estimates are corrected for regression to the mean. You will get very bad estimates without this approach.
The problem with demeaning each firm and is that it's equivalent to doing the very thing you don't want to do (estimating a different intercept for each firm). You're estimating the growth rate for each firm by using the observed (mean) growth rate. This is going to cause severe problems, and is in fact inadmissible (statistically unjustifiable) if you're estimating more than 3 firms.
For more details on random effects estimation (usually called hierarchical modeling from the Bayesian viewpoint), I suggest Richard McElreath's book, Statistical Rethinking.
