Hi all,
In order to generate spatial lags of variables, I have had to reduce the following dataset, which is id_region and time specific (I've omitted the irrelevant variables from the data extract to remain concise):
to a region time specific dataset:
I had to do this in order to generate spatially lagged variables, using code outlined here: https://www.statalist.org/forums/for...ing-spgenerate. I reduced the dataset like this, after having created region-time averages of the data:
However, I need these spatial lags in the original dataset, the one I had before I reduced it to a region-time specific dataset. The optimal course of action would be to merge this reduced dataset back with the original one and take the newly generate spatial lags, which then just have duplicates in the original id_region time specific dataset.
I tried the preserve and restore commands, but once restore has run, I lose the changes made and therefore the spatially lagged variables created.
I also tried, with the reduced dataset as master file
however this gave me nonsense results, although all the observations had matched (_merge==3 for all observations).
Please could someone let me know where I've gone wrong and how I could get back to the original dataset with the newly generated spatially lagged variables? I might be going about it wrong, merging may perhaps not be the way to go...
Many thanks in advance!
In order to generate spatial lags of variables, I have had to reduce the following dataset, which is id_region and time specific (I've omitted the irrelevant variables from the data extract to remain concise):
Code:
input float(tok_cant token1) byte canton float time 27 16 1 7 27 16 1 8 27 16 1 10 27 16 1 11 27 16 1 13 27 16 1 14 27 16 1 16 27 16 1 17 28 16 2 7 28 16 2 8 28 16 2 10 28 16 2 11 28 16 2 13 28 16 2 14 28 16 2 16 28 16 2 17 29 16 3 7 29 16 3 8 29 16 3 10 29 16 3 11 29 16 3 13 29 16 3 14 29 16 3 16 29 16 3 17
Code:
input byte region float time 1 1 1 2 1 3 1 4 1 5 1 6 1 7 1 8 1 9 1 10 1 11 1 12 1 13 1 14 1 15 1 16 1 17 1 18 1 19 2 1 2 2 2 3 2 4 2 5 2 6 2 7 2 8 2 9 2 10 2 11 2 12 2 13 2 14 2 15 2 16 2 17 2 18 2 19
Code:
bys region time: keep if _N==_n
I tried the preserve and restore commands, but once restore has run, I lose the changes made and therefore the spatially lagged variables created.
I also tried, with the reduced dataset as master file
Code:
merge 1:m region time using "originaldataset"
Please could someone let me know where I've gone wrong and how I could get back to the original dataset with the newly generated spatially lagged variables? I might be going about it wrong, merging may perhaps not be the way to go...
Many thanks in advance!
Comment