The shift reflects how the practice of medicine has been changing, too. Doctors used to essentially be small-business owners. As such, they may have been more attracted to Republican aims of low taxes and limited regulation. These days, more and more doctors are employees of large companies or hospitals.

Should you care if your doctor is a Democrat or a Republican? Maybe. Professor Hersh and Dr. Goldenberg used their data on doctors’ partisan identification to conduct a study of primary care physicians, published in the Proceedings of the National Academy of Sciences this week.

They asked the doctors to consider a group of hypothetical patients: one who smoked, one who drank, one who was overweight, and so on. They found that doctors viewed most of their patients’ health with similar seriousness and would advise similar responses. But for three of the hypothetical patients, they found differences. Those patients were devised to have health problems closely tied to hot-button political issues: One used marijuana, one owned guns, and one had a history of abortions. For those patients, Republican and Democratic doctors registered different levels of concern and said they would respond differently.

When it came to the patient with a history of abortions, doctors who were Republican said they would be more likely to encourage the patient to seek counseling and express concern about mental health consequences; they also said they would be more likely to discourage the patient from seeking future abortions. For the patient who used marijuana, Republican doctors said they’d be more likely to ask the patient to cut back and to discuss legal risks of using the drug, which is banned under federal and most state laws. For the patient with guns, doctors who were Democrats indicated they’d be more likely to tell the patient not to keep guns at home. Republican doctors, on the other hand, would be more likely to discuss safe storage options.

“These findings suggest you are going to get different care,” Professor Hersh said, adding that the differences might not matter much for the average patient. But they might for patients whose needs were closely related to politically divisive subjects, like reproductive health, with issues like contraception, abortion and prenatal screening; or H.I.V. prevention, with risk factors that include sex and intravenous drug use.

Primary care doctors and obstetrician-gynecologists, the doctors most likely to consider such issues, were among the most evenly split in the study sample. That means that patients probably can’t guess the political leanings of their doctor without asking (or checking the voter file data). The current study is only a survey, but Professor Hersh said he hopes the research spurs more examinations of how ideology shapes medical practice.

Professor Hersh and Dr. Goldenberg constructed the data set by assembling a large sample of doctors from the federal government’s National Provider Index, a file of every physician in the United States who either bills insurance or shares data digitally. There are very few doctors who are not included in this file.