Last active
October 30, 2018 17:57
-
-
Save Guerillero/a3002a7e492a3042aba58662ce27e2ed to your computer and use it in GitHub Desktop.
Merge an IR file with the GC (points) file in STATA
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/****************************************************************************************** | |
* Title: NigeriaMerge.do | |
* Created by: Tom Fish | |
* Created on: 30 October 2018 | |
* Purpose: Explan how to merge an IR file with the GC (points) file in STATA | |
******************************************************************************************/ | |
clear all | |
set more off | |
* Set folders that I am working on | |
local ptsDir "C:\08_GPS\04_Completed_Surveys\Nigeria\Nigeria_2015_MIS\Upload_file\" | |
local dataDir "C:\Data\DHSdata\" | |
local working "C:\Working\" | |
* Make sure we are working in our working directory | |
cd "`working'" | |
* Convert the shapefile into a dta file to merge in STATA | |
shp2dta using "`ptsDir'NGGE71FL.shp", database(ngpts) coordinates(ngcoord) genid(id) | |
* Open up the table portion of the shapefile | |
use ngpts | |
* Rename and sort to allow for the merge to be successful | |
rename DHSCLUST v001 | |
sort v001 | |
* Resave the table | |
save ngpts, replace | |
* Open the IR file | |
use "`dataDir'NGIR71FL.DTA", clear | |
* Do a 1 to Many merge/join by joining the GPS points (ngpts.dta) to the IR file | |
sort v001 | |
merge v001 using ngpts.dta | |
* Show that the merge was 100% successful and then drop the unneed column | |
tab _merge | |
drop _merge id | |
* Save the merged file | |
save NG_Merged, replace |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment