It is based on the equity the hand creates. Up front you should mix it up, with limps and raises. So will tell you to raise all the time to protect your hand. I don't find that you end up getting the necessary pot odds to make this play profitable often enough.
You need to learn to fold these hand from early position especially against an aggressive table. Loose table, limp often and hope to hit so you can cash big. Remember LOOK at the board, even though you might have top set you could be in a lot of danger, so sometimes coming with a large bet after flopping the set may be necessary to get rid of the draws.