Announcement

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

  • Spgenerate with panel data in Stata15

    I have a perfectly balanced dataset with 25 countries and 10 years correctly xtset and spset in Stata15 for a spatial regression analysis.
    I created a W connectivity matrix and, in order to save thm for other datasets and works, I would like to create some lagged variables with Spgenerate.
    Code:
    spmatrix create contiguity W if year==2007, normalize(row) replace
    There are no specifications for panel data in the manual (like the ones for producing the matrix by using an if) but when I try to create the lagged variable
    Code:
     spgenerate Wgdp =W*gdp
    Stata returns me the following msg:

    _IDs in weighting matrix W do not match _IDs in estimation sample
    There are places in W not in estimation sample and places in estimation sample not in W.


    I believe it has something to do with the panel structure, but I'm not at all sure, and I cannot figure out something different or a solution.

    NB Running a spxtregress with those same data does not produce any error, and Stata is able to estimate the model.

    Any suggestions?

    Thanks a lot

    Marco Giuliani

    PS I tried with diverse matrices, including idistance, and even the type of normalization chosen does not make any difference

  • #2
    -spgenerate- is not designed to generate spatial-lag for panel data. However, I think there is a work around for your problem. Basically, you can use -if- clause in -spgenerate- to generate a spatial lag for each time period.

    For example,

    generate Wy = .

    foreach t in 1 2 3 {
    capture drop tmp
    spgenerate tmp = W*y if time == `t'
    replace Wy = tmp if time == `t'
    }

    Comment

    Working...
    X