Capital Gains tax - offset loss vs gain

Can a loss in, say stocks, be used to reduce the tax due to gains in, say real estate, like in the USA?

In which country?

In Portugal, No you cannot offset loss from stocks against gains in real estate. Only if they are in the same category. Hope this helps!