I moved in the middle of the year. I made capital gains from stock sale while living in NYC and then had capital loss from stock sale after I moved to NJ. Usually I could offset capital gains with capital losses but given I moved, do I still need to pay capital gains tax to New York given there was no loss during my NY residency?
The capital losses will not offset, so you'll still have to pay capital gains tax to NY. A rough formula for NY part-year resident tax is:
tax on total income x (NY income / total income)
Your NY income will be unaffected by the capital losses. Your total income will go down, which means the tax on the left will go down, but the fraction on the right will go up. Hard to predict the overall effect, but it almost certainly won't be as favorable as if you could include the capital losses in your NY income.
Usually this would pretty much even out, as you'll pay more tax to the old state but less tax to the new state. However, NJ doesn't allow net capital losses (i.e. you can't offset regular income) and it doesn't allow carryover losses to offset capital gains realized in NJ in future years. So unfortunately the capital losses will only help with your federal income tax.