I'm still not sure if anyone knows how you get stars.
It truly remains one of our greatest mysteries.
Think the formula for three stars is something like this:
+ Time spent in first, 40 points (though some claim to have gotten 3 stars even with a second place finish in 1/4 races)
- Time spent going offroad (even though some shortcuts require you to do so, it's better to just stay on the track), out of bounds (lakitu'd) or hitting obstacles/walls
I don't think items or coins figures into it, but who knows. Just try to have a clean run and watch out for that asshole Wario throwing a bunch of shit at you, then knocking you off the last turn of Rainbow Road after you've been blue shelled-RUINING MINUTES OF HARD WORK...because I've heard that can happen.