Best ways to add healthy years to your life.

Will you live to 100 and beyond? Certainly genetics is a key factor, but the number of years that you actually accrue—and how healthy you are during those years—often are within your control.

Consider: The number of centenarians—people who live to the ripe old age of 100 or beyond—increased by 51% between 1990 and 2000. The average life expectancy in the US is now 78.8 years, a record high.

Improvements in health care deserve some of the credit, but personal choice is a strong predictor of how long you’ll live. About 70% of “normal,” age-­related declines—including those caused by heart disease, diabetes and other chronic diseases—are mainly due to lifestyle factors.

But which factors are the most important? Not smoking is one. But there are four other lifestyle changes that make the biggest difference when it comes to living a healthier, longer life. They’ll also improve your life right now by boosting your mood, energy and cognitive focus.

Exercise more as you get older

Some exercise is better than none, but it’s a myth that just a little exercise is enough. Walking to the mailbox or enjoying the occasional game of golf isn’t enough.

Everyone should exercise hard at least five days a week. Make it six days if you’re 50 or older. Tough workouts stress muscles, bones and blood vessels and cause adaptive ­microtrauma, small injuries that trigger the body’s self-repair mechanisms. Result: Healthier and stronger tissues.

A study that looked at 10,000 ­middle-aged men over a five-year ­period found that those who were fittest were three times less likely to die than those who were the least fit. Even more encouraging, men who were largely sedentary at the start of the study but who boosted their exercise levels reduced their mortality by half.

Suppose that you’re 30 pounds overweight and a smoker, but you exercise every day. You’ll still live longer than someone who is thin and doesn’t smoke but does not exercise. (Obviously, you’ll do even better if you give up the smokes and lose a few pounds.)

My advice: Lift weights a few days a week, and do serious aerobic exercise four days a week. You can vary your routine with other types of exercise such as yoga. Ideally, you’ll exercise for about 60 minutes each time. During the aerobic workouts, keep your heart beating at approximately 60% to 65% of your maximum heart rate—and faster as you get in better shape.

I also advise patients to join a gym, even if they would rather not. Many people think that they’ll get all of the exercise that they need by working out “informally”—by using a home treadmill, for example, or by going for runs or bike rides in the neighborhood. But most people don’t stick with it.

In my experience, a gym membership is a good investment. Once you’ve written a check, you’re already invested in making it work. Once you make it to the gym, you’re going to exercise—and it’s more fun to do it with others than alone.

Helpful: Sign up for classes or other group activities such as spin classes, aerobics sessions and Zumba that require you to be there at certain times. Or hire a personal trainer on a regular basis to give you a routine to follow.

Give up white foods

Sure, you’ve heard this before, but it bears repeating because it’s crucial to living longer. Give up or strictly limit white potatoes, white rice, white bread and white pasta. Even though “simple” ­carbohydrates have only about half the calories of fat, they’re more likely to cause weight gain because they act like pure sugar in the body. They cause surges in insulin that trigger inflammation and increase the risk for heart disease, diabetes and other chronic diseases.

Important: I don’t recommend formal diets for weight loss. Calorie control obviously is important, but strict dieting rarely works. Most people will lose weight just by giving up junk food—and white, starchy foods are junk. Replace junk food with natural foods that haven’t been processed or refined such as fruits, vegetables, whole grains, fish, etc.

Studies have shown that eating a ­Mediterranean-style diet (which actually is high in fat but includes the healthy foods above) is probably ideal for health as well as longevity. For more information on healthier eating, read Dr. Walter Willett’s book Eat, Drink and Be Healthy.

Log your life

Can you live longer just by writing down, every day, what you ate and how much you exercised? Surprisingly, the answer is yes.

Even though it’s a bit of a hassle, keeping a daily diary of health-related details is a sign that you care. It’s also a good form of accountability. You might be less likely to skip a day’s exercise or chug down a supersized soft drink when you know that you’ll have to confess it (if only to yourself).

The health software that now is ­standard issue on some smartphones makes it particularly easy to track your habits. The iPhone Health app, for example, automatically counts the number of steps you take and how far you have walked or run. You can use other features to track your weight and what you eat. I also like the apps MapMyRide (for ­cycling) and ­MapMyRun (for running).

Stay connected

People who have close friends and are engaged in their communities tend to live a lot longer than those who are loners. It makes sense because humans, like wolves, evolved as pack animals. We need people around us.

Single men, for example, have higher rates of heart disease and cancer than married men—and they tend to die years sooner. People who go home to an empty house ­after a heart attack are twice as likely to have a second heart attack within a few months. Those who are angry and isolated have four times the mortality rate of those who are happier.

My advice: Do whatever you can to connect with other people. Make plans with friends even when you would ­really rather be alone. Get involved in charities and other altruistic activities. Attend religious services. Take advantage of Meetup and other web-based social groups.

Obviously, someone who’s naturally solitary will never want to become the life of the party. That’s fine because what matters is the aggregate of your social connections. A few truly caring relationships can expand your life (and your life span) just as much as a wide social network.

Also, consider adopting a dog—or a cat, rabbit or bird. The emotional connections that we form with animals can rival, in terms of health benefits, those that we form with fellow ­humans.

One study, for example, looked at dog ownership in heart attack patients. People who didn’t have a dog were six to eight times more likely to die of a second heart attack than those who did.

Not a dog lover? That’s OK because any pet that you truly love and care for can offer the same benefits.