Skip to content

Instantly share code, notes, and snippets.

Last active Oct 30, 2018
What would you like to do?
Merge an IR file with the GC (points) file in STATA
* Title:
* 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