If I first do a two sided test (≠) and then do two one sided tests with different direction, should not the union of the found variables for the one sided tests be equal to the one from the two sided test? Will the p-value for the same variable differ for the two tests?

Answer

That will not be the case and the reason is best explained with an example. In this case for tests with a significance level of 0.05, but the level could of course be different.

For a two-sided t-test (obtained with the ≠ option), a variable obtains a p-value less than 0.05 if its t-statistic is in the top 2.5% or in the bottom 2.5% of the null distribution for the t-statistic. For a one-sided test with the ">" direction, a p-value less than 0.05 results if the t-statistic is in the top 5% of the null distribution. Similarly, for a one-sided test with the "<" direction, a p-value less than 0.05 results if the t-statistic is in the bottom 5% of the null distribution.

Following the same line of reasoning, the p-value for a two-sided t-test is the probability of obtaining a test statistic at least as extreme (in either direction) as the observed one under the null hypothesis, while the p-value for a one-sided t-test is instead the probability of obtaining a test statistic at least as extreme in a specified direction. Thus, for a test statistic with a symmetric null distribution, like the t-statistic, the two-sided p-value is twice as large as the appropriate one-sided p-value.