问题
I want to plot an interaction effect among two variables.
margins SentiSat_Rounded#PriceReduction
I get the following error:
'SentiSat_Rounded' not found in list of covariates
r(322);
The variables are present in the dataset. Also if the variable is not present in the dataset it throws a different error, like
variable X not found
Can you please suggest what is meant by not present in list of covariates?
To find covariates I came across this code: program covars, rclass version 8
capture local Covars : colnames e(b)
if _rc error 301
tempname b
mat `b' = e(b)
tokenize `Covars'
local k = 0
forval j = 1/`= colsof(`b')' {
if "``j''" != "_cons" & `b'[1,`j'] != 0 {
local covars "`covars'``j'' "
local ++k
}
}
if `k' {
di as txt "{p}`covars'{p_end}"
return local covars "`covars'"
c_local covars "`covars'"
}
end
I ran
covars
after that .. in the list of covariates, the above variable is not listed .. Is that list of covariates different from the variables in my dataset? How does Stata determine what is a covariate?
回答1:
The covariates are those used as such in the previous model. That is, margins
always follows a modelling command, in your case xtmixed
, and the covariates are the variables other than the response (first-named variable) named in that model call.
You may know covariates as predictors or even independent variables or through some other terminology. But for Stata covariates are certainly not just any variables in your dataset; they must have been named in your model call.
If this isn't clear to you, show us the exact xtmixed
command preceding your margins
call.
It shouldn't be surprising that Stata can't do anything with a variable not in the dataset!
来源:https://stackoverflow.com/questions/15402054/stata-error-not-found-in-list-of-covariates