I know how to control for sample selection bias when doing a regression. But what I dont know is that do we have to deal with sample selection problem when we are comparing the means of two groups?
It really depends on the particular situation. What kind of selection bias is relevant for the problem? Are you, for example, thinking about selection bias with regard to the units being selected into one of the groups?
Even if one should be careful, I would say that every statistical analysis is affected by the method used to select your samples.
If you have 2 groups and, for instance, you used a non-probabilistic approach to sample one of the group, your ANOVA analysis or t-test will be of course affected (if this is what you are trying to do when you cite "comparing the means of the groups").
A more precise statement of the problem could be helpful for a more precise answer.
If I were comparing the means of two populations for which I did not have auxiliary data, I would look at a confidence interval about the difference in the sample means. You would want to rely on randomization to hopefully control for bias in each sample.
If you have auxiliary data to use as regressor (independent variable) data, then you could predict means for each group. Randomization would still be helpful, but not so strictly necessary, as long as the regression model used for each group is appropriate. Stratification is always to be considered, so that each group itself is better representative, perhaps by such subgrouping.
On my ResearchGate contributions page, I have a number of papers involved in the estimation of totals from cutoff samples, and the approximately quarter century record of my use of this at the US Energy Information Administration showed good results for the use of prediction (regression) in estimating totals. But it really depends upon your applications and populations and circumstances.
Regardless, randomization and/or stratification can be very helpful.
Cheers - Jim
PS - You might be interested sometime in the following, though perhaps it only partially addresses your current concerns:
----------------------
Ken Brewer's Waksberg Award article:
Brewer, K.R.W. (2014), “Three controversies in the history of survey sampling,” Survey Methodology,
(December 2013/January 2014), Vol 39, No 2, pp. 249-262. Statistics Canada, Catalogue No. 12-001-X.