Hi everyone,

margins, atmeans saves the means of covariates of a model in a matrix r(at), see here:

Code:
// Open data
sysuse auto, clear
// Run regression model (1) of no further importance
qui regress mpg i.rep78 length trunk
// Calculate average mpg when holding covariates at their means
margins, atmeans
// Matrix including the means of covariates
matrix list r(at)
// Save matrix under the name cov_averages
matrix cov_averages = r(at)
What I want to do now is run the regression model (1) for different samples, say

Code:
// Run regression model (1) of no further importance for other (sub)sample
qui regress mpg i.rep78 length trunk if foreign == 1
And calculate my parameter of interest with the margins command (average mpg), holding the
covariates at the means as included in r(at) from regression model (1), as in

Code:
margins, at(~cov_averages~) if foreign == 1
(This latter thing of course doesn't work as indicated by the wishful thinking operator ~)

Is there a way to do this?


Thanks for your consideration
Klaus