However, if you've recently run another race at a different distance, one way to give yourself a rough estimate of what you're capable of running is to use a calculator, such as this race time predictor calculator on Running for Fitness. You just plug in your age, gender, and time/distance from a recent race. The calculator then shows you how you might perform in races at other distances. One thing I like about Running for Fitness's calculator is that it shows several different predictions, based on different formulas. So you get a range of predicted times, and you can see that it's not an exact science -- just an estimate.
You need to also keep in mind that the race time predictions are estimates of the time you might achieve, if you do the appropriate training for that distance. So it doesn't mean that if you train for a 5K and achieve a good time, then you'll automatically run the corresponding marathon time. In addition, as I said, there are so many variables that could affect your time. For example, no two courses are exactly alike, and running a hilly vs. flat course or high altitude vs. sea level, will definitely slow you down.
In my experience, I've found the predictions to be more accurate when the races are closer in distance. For example, you're more likely to get an accurate prediction for a marathon based on a half-marathon time, rather than a 5K. It's also good to use a time from a race no more than six weeks before your race. If it's more time than that, your fitness level may have changed (for better or worse) and the times won't be as accurate. Also, if you're running local races, running a race within a few weeks of your target race increases your chances of having similar weather conditions for both races, which will also make your time prediction more realistic.
There's obviously a large margin of error when using race predictor calculators, but it's helpful to have a rough estimate before a race, rather than going into it blindly. It can definitely keep you from setting race goals and prevent pacing mistakes, such as going out too fast.
Also see: What's a Good Time for a Marathon?
What's a Good Time for a 5K?