people panic when an earthquake strikes, they run to the door as they run they trample, trip, and injure themselves. While in both cases happen when things start falling down on you, you have a much more probability of being safe/uninjured while taking cover inside. And in most cases building nowadays have earthquake proof design that helps prevent the building from collapsing.
Exactly what @creativedragonbaby said, get under the most solid table you can find and stay there. The aftershocks come pretty quickly too soo be ready to stay for a while. Door frames depend on the house structure, they're usually fine but some homes are at risk of splitting
Source: I've been through a few massive earthquake in Chile
Go outside: building doesn't fall on you
If you can get outside in time, move away from buildings