Announcement

Collapse
No announcement yet.
X
  • Filter
  • Time
  • Show
Clear All
new posts

  • plotting conditional predicted mean and CI

    Hi.

    I have the following model:
    xtreg ln_price ratio ratio2 ratio3 ln_gdp ln_export, fe cluster(prod)
    (where fixed effects are at the product level, ratio2 is the squared value of ratio, and ratio3 is the cubic value of ratio).

    I would like to plot the relationship between "ratio" and "ln_price", where the predicted value of "ln_price" is computed at the average value of covariates ("ln_gdp" and "ln_export"). I would also like to plot the confidence intervals.

    Since I was not able to find a Stata command to compute the conditional predicted mean, what I am doing now is the following:
    Code:
    xtreg ln_price ratio ratio2 ratio3 ln_gdp ln_export, fe cluster(prod)
    matrix list e(b)
    scalar cons=_b[_cons]
    scalar b1=_b[ratio]
    scalar b2=_b[ratio2]
    scalar b3=_b[ratio3]
    scalar a1=_b[ln_gdp_pc_e]
    scalar a2=_b[ln_export_e]
    egen ln_gdp_mean= mean(ln_gdp_pc_e)
    egen ln_export_mean= mean(ln_export_e)
    gen yhat= cons+b1*ratio +b2*ratio2 +b3*ratio3 +a1*ln_gdp_mean +a2*ln_export_mean
    twoway (line yhat ratio)
    1) Is there a Stata command to compute the conditional predicted mean? I am using Stata14.

    2) How could I compute the confidence intervals in this case?
    Last edited by Simona Gamba; 14 Jun 2022, 05:37.

  • #2
    Simona, here is an example of plotting the predicted "ln_wage" against various values of "tenure", at the mean value of "hours".

    Code:
    webuse nlswork, clear
    xtreg ln_wage tenure hours, fe vce(cl idcode)
    
    margins, at(tenure=(0(5)25))
    marginsplot
    Click image for larger version

Name:	Graph.png
Views:	1
Size:	287.4 KB
ID:	1669139

    Comment

    Working...
    X