In response to my Google search “stata accessing e(sample) in mata” I received an “AI overview” which started with
Problematic but perhaps reassuring that our AI overlords aren’t ready to take power yet.
(This is a Mata-related issue, but I thought this might be interesting to general users)
You can access e(sample) in Mata by using the st_isdev() function, which retrieves the estimation sample as a boolean vector. However, a more common approach is to pass the sample information to Mata as a variable or matrix from Stata, as Mata is not designed to directly access Stata's internal macros.This seemed helpful until I realized that st_isdev() does not exist in Mata, nor does a boolean data type.
Method 1: Access with st_isdev()
This is a direct way to get the e(sample) variable, which contains a 0 or 1 for each observation.
- Call st_isdev() in your Mata code.
- This function returns a vector indicating which observations were in the estimation sample.
- Example: boolean sample = st_isdev()
Problematic but perhaps reassuring that our AI overlords aren’t ready to take power yet.
(This is a Mata-related issue, but I thought this might be interesting to general users)
