Ballot counting when ties occurs exactly $r$ times Ballot Problem with Fixed Number of Ties:
Problem Statement: In an election, candidate A receives $m$ votes and candidate B receives $n$ notes. Let $m \ge n$. In how many ways can the ballots be counted so that ties occur exactly $r$ times ($r \le n$)? 
Example: $m = 3, n = 2, r = 1$. There are 4 such scenarios: for order ABAAB, BAAAB the tie occurs at the 2nd vote; for order AABBA, BBAAA the tie occurs at the 4th vote. 
Call this number $Z( m,n, r)$. My practical goal is to answer the following:  Given the total number of votes $N$, how many ways can we order the ballots to have exactly $r$ ties? It is 
\begin{equation}
Z(N,r) = \sum_{n = r}^{N/ 2} Z( N-n, n ,r ) + \sum_{n = r}^{N/ 2} Z( n, N-n ,r )
\end{equation}
once we figure out $Z(m,n,r)$. 
It would be nice if one can get $Z(N,r)$ or its generating function directly, but I think the "$r$-tie" ballot problem is interesting on its own.
Mapping to lattice path enumeration
Here is an equivalent form of the problem: 
Consider lattice path from $(0,0)$ to point $(m,n)$ with only up $(0,1)$ or right $(1,0)$ movement in $m +n $ steps. Excluding the starting point $(0,0)$, how many lattice paths hit the (lattice point on the) diagonal line $y = x$ exactly $r$ times? 
The following figure shows a lattice path that reaches (4,3) and its image under Andre's reflection. It hits the diagonal 3 times. 

$r = 0$ is the strictly monotonic path
The $r = 0$ problem can be solved by Andre's reflection principle. (method used here is similar to this ME post)
First of all $m > n$, otherwise the end point $(n,n)$ will be one touching point. Since no touching of the diagonal is allowed, the first step must go right. There are ${ m + n - 1 \choose m-1}$ such paths but we need to exclude the ones that touches the diagonal. 
Suppose there is one such path (first step going right) that touches the diagonal, we can do reflection about the $ y= x$ line for the path between the origin and the first intersection (see Figure). The reflected path is one that starts with up movement. Since such paths will definite cross the diagonal line to reach $(m,n)$, it is easy to see that the map is one-to-one. There are ${m+n -1 \choose n - 1}$ such paths. 
In sum, the result is
\begin{equation}
Z( m, n, 0) = { m + n - 1 \choose m - 1 } - {m+n -1 \choose n - 1} = { m + n - 1 \choose n } - {m+n -1 \choose n - 1} \quad m > n 
\end{equation}
which is very similar to the ballot theorem. 

Any idea of approaching the general $r$? 
Thanks! 

Update 1: $m = n, r = 1$ is the strictly monotonic Dyck path
The only intersection is at the end point $(n,n)$, so this is basically a Dyck path that hits the diagonal once. This ME post gives the general result for a Dyck path to hit the diagonal $k$ times. Setting $k$ = 1, the result is $\frac{1}{n}{2n - 2 \choose n-1 }$. Here the path can be either above or below the diagonal line, hence a factor of $2$,
\begin{equation}
Z( n, n, 1 ) = \frac{2}{n}{2n - 2 \choose n-1 }
\end{equation}

Update 2: number of lattice paths that crosses the diagonal $k$ times
Call this number $C( m, n, r )$. 
Kern, Malcolm; Walter, Stanley, Ballot theorem and lattice path crossings, Can. J. Stat. 6, 87-90 (1978). ZBL0387.60018. gives the result
\begin{equation}
C( m,n, r ) = \left\lbrace
  \begin{aligned}
    &\frac{2(r+1)}{n} {2n \choose n - r -1 } & m = n \\
    &\frac{m - n + 2r + 1}{m + n + 1} { m + n +1  \choose n - r } & m > n \\
\end{aligned}  
\right.
\end{equation}
This is a relevant but different problem. Notice the difference between "touch" and "cross". Only going from one side of $y=x$ to the other is considered as a "cross". In the ballot problem, this is a change of the leading candidate, not a tie. One can check that $C( n, n, 0 )$ is twice the Catalan number. 
 A: I came up with a visual proof of
\begin{equation}
Z(m,n, r ) = 2^r \frac{m - n + r}{m + n - r} { m + n - r  \choose n- r }
\end{equation}
that is mush easier than my generating function approach. I think it deserves a separate answer. 
The $2^r$ factor
Divide a lattice path of $r$ intersections with the diagonal into $r$ segments where the $i$-th segment is between the $i$-th intersection point and the $i+1$-th. 
Each segment is a lattice path that intersects the diagonal only at the end point and there are two possibilities: going above or blow the $ y = x$ line. Hence we can consider only the lattice path below $y = x$ (shown in left figure below). Call the corresponding number of lattice paths to be $Z_{-}( m,n, r )$, we have
\begin{equation}
Z( m, n, r ) = 2^r Z_{-} ( m, n, r ) 
\end{equation}

Reduction to $r = 0$
Take a lattice path below the line $ y= x$. At all the intersection points, the preceding step must be going up (labeled blue in the left figure). 
If we remove those blue steps, we end up with a path on the right figure that starts from $(0,0)$ and ends at $(m, n - r)$. This path will not hit the diagonal $y = x$. On the other hand, we can also reconstruct the original path by drawing backwards and complementing a blue step when hitting diagonal. For the example in the right figure, we first move the last red step "going right" to the place between $(m-1,n)$ and $(m,n)$. If it hits the diagonal(it does), we complement a blue step; otherwise we pick up the previous red step. 
This procedure establish a one-to-one correspondence between the path from $(0,0)$ to $(m,n)$ below $ y= x$ that hits the diagonal $r$ times, with the path from $(0,0)$ to $( m, n-r)$ that does not hit the diagonal at all. 
Equivalently,
\begin{equation}
Z_{-} ( m, n, r ) = Z( m, n -r, 0)
\end{equation}
Conclusion
We therefore conclude that 
\begin{equation}
Z(m,n, r ) = 2^r Z(m,n-r, 0) = 2^r \left[ { m + n - r - 1\choose n- r }-{m + n -r -1  \choose n- r - 1 }\right]
 = 2^r \frac{m - n + r}{m + n - r} { m + n - r  \choose n- r }
\end{equation}
