When baking, butter triumphs over margarine.
For cakes, cookies, and pastries, butter (unsalted) provides richer flavor. It is originally a cream while margarine is made from vegetable oil. Butter's high fat content is also what gives baked goods their texture. Margarine, which can contain more water and less fat, may make thin cookies that spread out while baking. Margarine may also contain milk.
Butter is also the better choice for frying. Because it's more resistant to being broken down by heat butter doesn't become gummy the way unsaturated oils do.
*If choosing margarine for cooking*
If you're still sold on using margarine, make sure you read the nutrition label. If you see "hydrogenated," that means the product contains trans fatty acids. Many stick margarines include these enemies of good cholesterol. So choose a tub margarine that hasn't been hydrogenated.