Announcement

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

  • Predict after spivregress

    Dear All,

    I estimate a spatial IV model. Then, I would like to predict the fitted values, using a different dataset, using predict. However, when I try to run the prediction, I get the following error message:

    Code:
    prediction sample must be a subset of e(sample)
    The new dataset is identical to the previous one. It contains the same areas, the same spatial matrix, the same names of the variables. Do you have an idea why this happens?

    Thanks in advance,

    Dario

  • #2
    Dear All,

    just a better explanation of my problem.

    I have one dataset, say A, which I use to estimate a spatial IV model. The dataset contains two exogenous variables, one endogenous regressor and two instruments. I estimate a SARAR IV. After the estimation, I upload a new dataset, say B, which contains different values for the exogenous and endogenous variables (although they have exactly the same names). The two dataset are identical in term of the spatial units and the spatial matrix.

    My objective is to use the new values to predict the dependent variable. If I type:

    Code:
    predict fitted
    I get the following error message:

    Code:
    prediction sample must be a subset of e(sample)
    r(498)
    Instead, if I type

    Code:
    predict fitted if e(sample)
    I obtain:

    Code:
    _IDs in weighting matrix dW1500 do not match _IDs in estimation sample
        There are places in dW1500 not in estimation sample and places in estimation
        sample not in dW1500.
    where dW1500 is the spatial matrix.

    Now the new dataset does not have gaps and as I mentioned before, it contains the same spatial units and variables with the same names. So, apprently, it is virtually impossible that there are places in dW1500 not in the estimation sample and places in estimation sample not in dW1500. I tried to generate in the new dataset again the spatial matrix, which is exaclty the same as the one in dataset A.

    Does someone know why I get those error message? Is it possible to predict the outcome variable using another dataset after a spatial regression?

    Thanks in advance for your help.

    Dario

    Comment


    • #3
      I suspect this can be done, but unless there is a user who regularly estimates spatial models, you'd get better responses by providing a reproducible example using one of the Stata datasets. You should create a second dataset that represents observations for the out-of-sample predictions.

      Comment

      Working...
      X