Hi list,

I am currently working on a project that envolves me using the Mixed command. The model includes a lot of variables and takes several hours to run. Therefore, I thought it would be smart to save the estimates so that I don't have to run the model in the begining of every session. I work on a protected server with no internet and Stata version 16.1

After having estimated my model I write
Code:
 estimates save fullmodel
I notice that a file called fullmodel.ster is created in my working folder.


In a new session - where i have the exact same data loaded that I used when estimating the model - I write
Code:
estimates use fullmodel
estimates esample
Stata tells me that e(sample) is not set (0 assumed).

When I attempt to calculate predicted values for different subgroups using margins I obtain the follwoing error:

" e(sample) does not identitfy the estimation sample r(322);"


Under the documentation for [R] estimates save I read that when I utilize estimation use Stata thinks that none of the observations in the data was used in producing the estimates currently loaded.

It also says that "There are some postestimation statistics that are appropriate only when calculated on the estimation sample. Setting e(sample) to 0 ensures that if you ask for one of them, you will get back a null result"

Is this what I have encountered? Does margins need the sample to run?

The documentation suggests that you can define the sample as everyone who has non-missing values in the variables included in the model. However, I believe that Mixed allows for units to have some missing values in included variables and therefore it would not work in this case.

With basis in this link https://stats.idre.ucla.edu/stata/faq/how-can-i-identify-cases-used-by-an-estimation-command-using-esample/ I try the following after having estimated my model:

Code:
gen sample = e(sample) // generates variable=1 if unit was used to calculate model I believe?
save "data_post_estimation.dta", replace // saves data with the new variable
estimates save fullmodel // saves estimation

In another session where I want to work with the estimation results:

Code:
use "data_post_estimation.dta", clear
estimates use fullmodel
estimates esample: if sample // I believe this tells stata that the sample is the units with the value of 1 in this variable?
Stata allows me to calculate margins: Is this a meaningful solution?
I am not certain I understand what happens - is there a more correct way to go about this?

Best,
Mads