When is it "allowed" to combine two samples in linear regression? I have two datasets, from several experimental campaigns, which relate the controlling variable X to the dependent variable Y.
Therefore, I have ($X_{i}$;$Y_{i}$), for the i-th dataset.
Dataset 1 is my reference, and I intend to join the datasets.
Some of the datasets $i=2,...,n$ look pretty overlapped with the dataset 1, others do not. But I cannot just do it "by eye".
I would like to know if there is a test that allows me, once I define a certain significance level, to establish whether the generic dataset $i$ can be joined with the dataset 1. In other words, I would like to know which statistical test tests the hypothesis for generic dataset $i$ to be drawn from the same population of the dataset 1.
 A: I'd argue that this is an ill-posed question.
Imagine that there existed a test that would tell you if two samples are "the same", or not. If the samples were the same, this would mean that you'd get the same estimates for the regression parameters, so there would not be any point in joining them, since the only thing that you'd gain are narrower confidence intervals.
Consider other scenario, where you get the data from unknown source. Imagine that the two datasets were in fact the same data repeated twice. In such case, the test would tell you that they are "the same", but using same data twice would be a bad idea, leading to overconfident results.
Instead of testing, you should rather consider how were the samples obtained and if joining them would not bias your results anyhow. For example, if you had small random sample and a bigger non-random one, then joining them without doing anything about this may not be the best idea.
Finally, if you decide that it makes sense to join the samples, you can use a dummy variable to encode which sample does the data come from and include it (and interactions with it), to see if it does any impact on the results (non-zero coefficients). If you find it does, you should check how big is it's impact (size of coefficients, how much does it change the results) and how much that hurts you.
A: As a general rule, we should always posit a single model that describes all the data under consideration.  So it is not a matter of deciding when we are "allowed" to model both sets of data together, it is a matter of figuring out how to do so.
If you are considering conducting linear regression then presumably your goal is to make an inference about the conditional distribution of the response variable $Y_i$ conditional on the explanatory variable $X_i$.  If you are combining two different datasets then you need to consider whether there is some other implicit covariate that differs between the two cases, that should be included in the regression.  The most obvious thing to do would be to include both datasets with a nominal variable specifying which dataset each datapoint comes from --- you can then test whether there is significant evidence of any model terms involving this variable (e.g., main effect, interaction effect, etc.).  You will ultimately need to consider whether and how you can model your response based on the two datasets, and whether this model is reliable.
