What is the ATE in the output of stata with psmatch2 or teffects psmatch It has been known that we can not get ATE from MatchIt package with method = "nearest" in R because  What is the purpose of using MatchIt in R with nearest neighbors for estimation of ATE if it does not report which pairs are matched?  said that "the covariate distribution of the matched samples will be similar to that of the treated group, and therefore the estimated effect is not generalizable to the population at large".
And also when I used Matching package in R with estimand="ATE" in 1:1 nearest neighbor matching, it calls
Warning message:
In Match(Y = example$death, Tr = example$trt, X = example$ps, M = 1,  :
  replace==FALSE, but there are more (weighted) control obs than treated obs.  Some control obs will not be matched.  You may want to estimate ATT instead.

and the matched data seemed wrong.
But when we use psmatch2 and teffects psmatch in stata,  ATE can be output smoothly.
So what exactly is the ATE in stata output and how is it generated algebraically?
 A: The default in Matching and teffects psmatch is to match with replacement. This means that every unit can receive a match, even if it is a member of the larger group.
To estimate the ATE using matching, you find a match for each unit in the opposite group, for both the treated and control groups. So, for each treated unit, you find a match in the control group, and for each control unit, you find a match in the treated group. Then you compute the following estimate:
$$
\tau_{ATE} = \frac{1}{N}\sum_{i=1}^N {\tilde{Y}_{1i}-\tilde{Y}_{0i}}
$$
Where
$$
\tilde{Y}_{1i}=\begin{cases}Y_{i} & A_i=1\\ Y_{Mi} & A_i =0 \\ \end{cases} \\
\tilde{Y}_{0i}=\begin{cases}Y_{Mi} & A_i=1\\ Y_{i} & A_i =0 \\ \end{cases}
$$
where $A$ is the treatment variable and $Y_{Mi}$ is the outcome of the unit matched to unit $i$ (or the average of such values if multiple units are matched to unit $i$ in $k$:1 matching).
You cannot compute the ATE when matching without replacement because not all units will receive a match; if the control group is larger than the treated group, there won't be enough treated units to provide matches to the control units.
If you want to estimate the ATE using matching with replacement, you can do this in Matching and teffects psmatch using the default settings. This is not allowed in MatchIt, but it is possible by performing two matches, one after switching the treated and control labels, though effect estimation will no longer be straightforward, so using Matching is recommended. If you want to estimate the ATE using MatchIt, it is possible to do so using full matching or propensity score subclassification.
