Hi,
I try to figure out what Stata (15.0) exactly does when calculating margins for a regression model with factor variables. Below you can find my calculations: model A and B are easy to understand, margins and display command show the same results. But model C has a factor variable and I don't know how to calculate the correct value via the display command. How does Stata handles (adjusts) the factor variable within my margins command?
---
sysuse auto, clear
* A) 1 continous independent variable
reg price weight
margins, at(weight=(2000))
display _b[_cons] + _b[weight] * 2000
* B) 2 continous independent variable
reg price weight length
margins, at(weight=(2000))
su length if e(sample)
display _b[_cons] + _b[weight] * 2000 + _b[length] * `r(mean)'
* C) 2 independent variables: 1 continous & 1 factor
generate length2 = recode(length,180,200,233)
replace length2 = 1 if length2 == 180
replace length2 = 2 if length2 == 200
replace length2 = 3 if length2 == 233
reg price weight i.length2
margins, at(weight=(2000))
display _b[_cons] + _b[weight] * 2000 + ???
I try to figure out what Stata (15.0) exactly does when calculating margins for a regression model with factor variables. Below you can find my calculations: model A and B are easy to understand, margins and display command show the same results. But model C has a factor variable and I don't know how to calculate the correct value via the display command. How does Stata handles (adjusts) the factor variable within my margins command?
---
sysuse auto, clear
* A) 1 continous independent variable
reg price weight
margins, at(weight=(2000))
display _b[_cons] + _b[weight] * 2000
* B) 2 continous independent variable
reg price weight length
margins, at(weight=(2000))
su length if e(sample)
display _b[_cons] + _b[weight] * 2000 + _b[length] * `r(mean)'
* C) 2 independent variables: 1 continous & 1 factor
generate length2 = recode(length,180,200,233)
replace length2 = 1 if length2 == 180
replace length2 = 2 if length2 == 200
replace length2 = 3 if length2 == 233
reg price weight i.length2
margins, at(weight=(2000))
display _b[_cons] + _b[weight] * 2000 + ???
Comment