Have there been any scientific studies that show whether or not spending money on advertising and campaigning has an effect on the outcome of an election? I can think of several elections where the candidates spent a lot but did not win. Are there any studies that show how effective political advertising is?
Sure. That is one of the biggest topics which was explored by political scientists in the first half of 20th century. You may want to check works of behavioralists which studied behavior of voters and the influence of political campaigns on them. Check Lazarsfeld`s works for example.
These studies showed that political advertising do not necessarily change voters' mind, they reinforce them (i.e those voters which had their opinions formed before the campaign started). But you may influence views of those people who did not have any strong opinion before electoral campaign.
TL;DR it depends on how you define "effective." There have been a fair number that generally speaking try to draw connections between advertising and process measures (i.e. turnout or likelihood of an individual to vote for candidate x), if that is what you mean. Obviously a type of analysis that could relate advertising with probability of victory is hard because of the obscene endogeneity (the candidate that is more likely to win probably has more money to begin with). I would not find such an analysis trying to relate ad spending and probability of victory very compelling because random assignment is more or less impossible and a sample size of "good" candidates who do not spend much is likely very small. This is limited to the U.S.
The main way advertising can be "effective" is by increasing turnout either by making a (usually House or Senate) candidate more known or getting people to care more (which is a major goal of negative ads). The evidence is mixed. Using NES data of the 2000 election, Freedman et. al. and Hillygus find significant (practically and statistically) effects, especially among certain demographics. Note that this is survey data and subject to, for example, recall bias. Malloy and Pearson-Merkowitz analyzed evidence from the Wisconsin Advertising Project for the Gubernatorial, Senatorial, and Presidential elections 1996 - 2008 and find that negative ads don't help but positive ads may help someone who is already ahead.
From what I can glean from that evidence, I find the thesis of Franz and Ridout rather compelling and consistent with most of the analysis. Specifically, advertising seems to have large effects on those who have less political knowledge, but limited effects on the politically engaged.