Living in a large metropolitan area can be very expensive. The cost of housing can be especially daunting.

One of the toughest financial decisions you will need to consider when moving to a big city is: Should you rent, or should you buy a place to live?

Home ownership is often seen as part of the American dream but in large metro areas the high cost of home prices can be a big deterrent. And increasingly high rental costs are also making it difficult for many families to afford to live in larger cities.

Nationally, it is more affordable to own a home with a mortgage than it is to rent, according to the Urban Institute, a non-profit social and economic policy research think tank.

A median-income family spends 28% of its income to pay the median rent for a 3-bedroom house, according to the research organization. That compares to spending 25% of your income for a monthly mortgage payment — principal, interest, taxes and insurance — on a median-price home bought with a 30-year fixed rate of 3.97% and a 3.5% down-payment. That is reduced to 22% of income if you put down a 20% down payment. (The median is the midpoint value where there are an equal number of values above and below.)

More:8 questions to ask yourself when deciding to rent or buy a house

More:Want financial security? Home equity and retirement accounts are key

But the affordability equation between renting and owning can vary widely across the country. As interest rates rise, the affordability issue is becoming more of a problem for more cities, says Bing Bai, research associate for the Urban Institute’s Housing Finance Policy Center.

In a new study, the research center found that it is actually more affordable to rent than to own in 16 of the 33 largest metropolitan areas.

The study looked at large metropolitan statistical areas (MSA’s) for home purchase and rental affordability and calculated the “rent gap” – the difference between the cost of owning and renting.

The city with the largest rent gap, or where it is more affordable to rent than to own, is the San Francisco area.

The West Coast city has a whopping rent gap of 43%: A median-income family in the area would spend 80% of its income to pay the monthly mortgage on a median-price home with a 3.5% down payment. That compares to the family spending 37% of its income on the median rent for a 3-bedroom house. The homebuyer would be paying an additional 43% of its income toward housing when compared to a renter.

“But even though it is cheaper to rent in San Francisco that does not mean it is still affordable for many people,” said Sarah Strochak, research assistant for the Housing Finance Policy Center. It just means that a greater portion of your income would be going to housing costs when owning a home than when renting.

The median rent for a 3-bedroom house in the area runs $3,450 a month.

The trend is similar in many other large West Coast cities, but not as extreme as in San Francisco. Here are the 16 metropolitan statistical areas where it is more affordable to rent than to own, as determined by the Urban Institute’s rent gap calculations:

San Francisco, Calif.: 42.5%

San Jose, Calif.: 19.1%

Seattle, Wash.: 8.6%

San Diego, Calif.: 7.0%

Sacramento, Calif.: 6.5%

Los Angeles, Calif.: 5.0%

Portland, Ore.: 5.0%

Riverside-San Bernardino, Calif.: 4.2%

Las Vegas, Nev.: 2.5%

Phoenix, Ariz.: 1.8%

Baltimore, Md.: 1.7%

Denver, Colo.: 1.5%

Washington, D.C.: 1.5%

St. Louis, Mo: 0.5%

Dallas-Fort Worth, Texas: 0.3%

Charlotte, N.C.: 0.1%

One thing to consider before abandoning the idea of owning a home in one of these areas is that the study does not take into account any tax benefits you would receive from home ownership. Tax benefits include deductions for mortgage interest, property taxes and private mortgage insurance.

More:What are the tax benefits of buying a home?

More:5 big tax breaks for homeowners

17 cities where it’s more affordable to own than rent

In contrast, the study found that it is more affordable to own a home than to rent in 17 of the 33 areas examined.

The Miami-Fort Lauderdale metropolitan area had the nation’s largest negative rent gap: A median-income family in the area would save almost 11% of their income if they bought the median-priced home with 3.5% down instead of renting.

Here are the 17 cities where it is cheaper to buy than rent:

Miami-Fort Lauderdale, Fla.: -10.9%

Detroit, Mich.: -7.1%

Chicago, Ill.: -5.6%

Philadelphia, Pa.: -5.0%

Tampa-St. Petersburg, Fla.: -4.6%

Pittsburgh, Pa.: -4.5%

Cleveland, Ohio: -3.5%

Cincinnati, Ohio: -3.4%

Orlando, Fla.: -3.2%

Houston, Texas: -2.5%

San Antonio, Texas: -2.3%

New York City, N.Y.: -1.8%

Minneapolis-St. Paul, Minn.: -1.5%

Kansas City, Mo.: -1.4%

Columbus, Ohio: -1.1%

Boston, Mass.: -0.6%

Atlanta, Ga.: -0.1%

Buying a house is challenging for many people since it can still be difficult to get a mortgage unless you have pristine credit, according to Bai and Strochak.

Adding to the problem of home ownership affordability is the lack of housing supply:

“We are not keeping up building for our needs and that will keep home prices high,” Bai said.