Hello,
I have two datasets. I have a Maindata which I would like to split into around 40 datasets based on a criteria in a separate dataset. Both datasets contain longitudes and latitudes and the criteria dataset specifies the range for a given group. So it has around 40 observations. This is the main dataset.
This is the criteria dataset.
A variable id=_n has been defined for the Criteria. I am trying to run a for loop such that the code iterates over each of 40 observations (ie criteria) in the criteria dataset and create separate datasets in the Maindata based on the longitudes and latitudes given there. This is the code I used:
However, I get a syntax error with the for loop. It says invalid syntax. Could someone please explain what's wrong? Thanks!
I have two datasets. I have a Maindata which I would like to split into around 40 datasets based on a criteria in a separate dataset. Both datasets contain longitudes and latitudes and the criteria dataset specifies the range for a given group. So it has around 40 observations. This is the main dataset.
Code:
Name Census2001_Lat Census2001_Lon "ABC" 12.747113 79.847343 "DEF" 12.874169 79.653198 "GHI" 12.87979 79.675159 "JKL" 12.867902 79.66732 "MNO" 12.721048 79.753166
Code:
clear Groups maxlat minlon minlat maxlon "GroupA" 12.95 79.18333333333334 12.633333333333333 79.75 "GroupB " 12.816666666666666 79.11666666666666 12.483333333333333 79.36666666666666 "GroupC " 13.783333333333333 78.96666666666667 13.4 79.58333333333333 "GroupD " 13.516666666666668 78.8 13 79.31666666666666
Code:
use Criteria forval i=1/`id'{ preserve use if (inrange(Census2001_Lon,`minlon',`maxlon') & inrange(Census2001_Lat,`minlat',`maxlat')) using MainData save data_`id', replace restore }
Comment