Seattle pediatrician Rupin Thakkar's first inkling that the pharmaceutical industry was peering over his shoulder and into his prescription pad came in a letter from a drug representative about the generic drops Thakkar prescribes to treat infectious pinkeye.

In the letter, the salesperson wrote that Thakkar was causing his patients to miss more days of school than they would if he put them on Vigamox, a more expensive brand-name medicine made by Alcon Laboratories.

"My initial thought was 'How does she know what I'm prescribing?' " Thakkar said. "It feels intrusive. . . . I just feel strongly that medical encounters need to be private."

He is not alone. Many doctors object to drugmakers' common practice of contracting with data-mining companies to track exactly which medicines physicians prescribe and in what quantities -- information marketers and salespeople use to fine-tune their efforts. The industry defends the practice as a way of better educating physicians about new drugs.

Now the issue is bubbling up in the political arena. Last year, New Hampshire became the first state to try to curtail the practice, but a federal district judge three weeks ago ruled the law unconstitutional.

This year, more than a dozen states have considered similar legislation, according to the National Conference of State Legislatures. They include Arizona, Illinois, Kansas, Maine, Massachusetts, New York, Nevada, Rhode Island, Texas, Vermont and Washington, although the results so far have been limited. Bills are stalled in some states, and in others, such as Maryland and West Virginia, they did not pass at the committee level.

The concerns are not merely about privacy. Proponents say using such detailed data for drug marketing serves mainly to influence physicians to prescribe more expensive medicines, not necessarily to provide the best treatment.

"We don't like the practice, and we want it to stop," said Jean Silver-Isenstadt, executive director of the National Physicians Alliance, a two-year-old group with 10,000 members, most of them young doctors in training. (Thakkar is on the group's board of directors.) "We think it's a contaminant to the doctor-patient relationship, and it's driving up costs."

The American Medical Association, a larger and far more established group, makes millions of dollars each year by helping data-mining companies link prescribing data to individual physicians. It does so by licensing access to the AMA Physician Masterfile, a database containing names, birth dates, educational background, specialties and addresses for more than 800,000 doctors.

After complaints from some members, the AMA last year began allowing doctors to "opt out" and shield their individual prescribing information from salespeople, although drug companies can still get it. So far, 7,476 doctors have opted out, AMA officials said.

"That gives the physician the choice," said Jeremy A. Lazarus, a Denver psychiatrist and high-ranking AMA official.

Some critics, however, contend that the AMA's opt-out is not well publicized or tough enough, noting that doctors must renew it every three years.

The New Hampshire court's ruling has raised new doubts about how effective legislative efforts to curb the use of prescribing data will be, but the state attorney general has promised to appeal. And state Rep. Cindy Rosenwald (D), the law's chief sponsor, vowed not to give up the fight.

"In this case, commercial interests took precedence over the interests of the private citizens of New Hampshire," Rosenwald said. "This is like letting a drug rep into an exam room and having them eavesdrop on a private conversation between a physician and a patient."

The April 30 ruling by U.S. District Judge Paul Barbadoro, nominated to the federal bench in 1992 by President George H. W. Bush, called the state's pioneering law an unconstitutional restriction on commercial speech.

Since at least the early 1990s, drug companies have used the data to identify doctors who write the most prescriptions and go after them the way publishers court people who subscribe to lots of magazines. They zero in on physicians who prescribe a competitors' drug and target them with campaigns touting their own products. Salespeople chart the changes in a doctor's prescribing patterns to see whether their visits and offers of free meals and gifts are having the desired effect.

"It's a key weapon in determining how we want to tailor our sales pitch," said Shahram Ahari, a former drug detailer for Eli Lilly who is now a researcher at the University of California at San Francisco's School of Pharmacy. "The programs give them [doctors] a score of 1 to 10 based on how much they write. Once we have that, we know who our primary targets are. We focus our time on the big [prescription] writers -- the 10s, the 9s, and then less so on the 8s and 7s. . . . We're dealing with individual physicians who might give us the biggest dividend for our investment."

Ahari said he used the data to tout the virtues of Eli Lilly's antidepressant Prozac to doctors who favored the rival drug Effexor -- noting, for example, that its longer half-life meant that if patients missed a dose over a weekend, they would experience less severe agitation and other withdrawal symptoms that might prompt them to call their doctor. He did not mention the rival drug by name or disclose that he knew the physician's prescribing habits, he said.

Data-mining companies and the pharmaceutical industry argue that the practice has value far beyond the corporate bottom line. The information helps companies, federal health agencies and others educate physicians about drugs, track whether prescribing habits change in response to continuing medical education programs, and promote higher-quality care, they say. They stress that patient names are encrypted early in the process and cannot be accessed, even by the data-mining companies.

A drug company might use the database to help determine whether physicians prescribing a particular high-risk drug have undergone required training about the medicine, said Marjorie E. Powell, senior assistant general counsel for the Pharmaceutical Research and Manufacturers of America, a trade association.

"If you don't have that information, then you are in a very difficult situation," Powell said. "There is no way you can implement the risk-management plan that the FDA [Food and Drug Administration] is requiring you to implement in order to allow the drug to be on the market."

The prescribing data also let "the company do more targeted marketing, which lowers the total costs of its marketing," she said.

Randolph Frankel, a vice president at IMS Health Inc., the Connecticut-based health-data-mining company that challenged the New Hampshire law, said the more a drug representative knows about a physician, the easier it is to provide information that meets the needs of the doctor's practice.

"We are about more information and more education, and not less," said Frankel, whose company had operating revenue of $1.75 billion in 2005, not all of it from sales to drugmakers. "The vast majority of physicians welcome these people as part of the overall educational process about drugs and their use. And any doctor in the country can close the door to these sales reps. It doesn't require legislation to do that."