Hi everyone, i am preparing a panel dataset to run analysis for my research project. The data files come separately and i have to combine them into one. This i have done using "merge" command functionality in Stata version 14. (Please find my attached do file). The merged dataset looks ok,..yet my programming is hazy and i am sure there can be a better method and i need t perfect my do file. Any contributions will be most helpful. Find the command and the dataset
//COMBINING WWAVE 1 PANEL STUDY
clear
cap log close
set more off
cd "C:\Users\MCFADDEN\Documents\DISSERTATION WRITING 2019\NIDS DATASETS\WAVE 1\Stata14"
log using "National Incomes Data Preparation.log" , text replace
//IMPORTING AND PREPARING WAVE 1 DATA FILES AND MERGING THEM INTO ONE FILE
//USING HOUSEHOLD QUESTIONNAIRE AS MASTER DATASET AND MERGE USING HOUSEHOLD ROASTER
use "HHQuestionnaire_W1_Anon_V7.0.0.dta", clear
duplicates report w1_hhid
duplicates drop w1_hhid if w1_hhid>1, force
sort w1_hhid
merge 1:m w1_hhid using "HouseholdRoster_W1_Anon_V7.0.0.dta", update
drop _merge
save householdfile.dta, replace
///ADDING THE HOUSEHOLD DERIVED FILE
clear
use "hhderived_W1_Anon_V7.0.0.dta", clear
sort w1_hhid
merge 1:m w1_hhid using "householdfile.dta", update
drop _merge
save "household_hhderived.dta", replace
//ADDING THE ADMIN FILE
clear
use "Admin_W1_Anon_V7.0.0.dta", clear
duplicates drop w1_hhid, force
merge 1:m w1_hhid using "household_hhderived.dta", update
drop _merge
save household_admin_roster.dta, replace
///ADDING THE PROXY FILE
clear
use "Proxy_W1_Anon_V7.0.0.dta", clear
sort pid w1_hhid
merge 1:m pid using "household_admin_roster.dta", update
drop _merge
save "household_admin_roster_adult_child_indder_proxy.d ta", replace
//ADDING THE ADULT QUESTIONNAIRE
duplicates drop pid, force
sort pid
merge 1:m pid using "Adult_W1_Anon_V7.0.0.dta", update
drop _merge
save household_admin_roster_adult.dta, replace
///ADDING THE CHILD DATASET
clear
use "Child_W1_Anon_V7.0.0.dta", clear
sort pid
merge 1:m pid using "household_admin_roster_adult.dta", update
drop _merge
save household_admin_roster_adult_child.dta, replace
///ADDING THE DERIVED DATA FILe
clear
use "indderived_W1_Anon_V7.0.0.dta", clear
sort pid w1_hhid
duplicates drop pid w1_hhid, force
merge 1:m pid using "household_admin_roster_adult_child.dta", update
drop _merge
save "nids_wave1.dta", replace
Please follow the link below to access the panel dataset from my drive, as i was not able to upload it here. https://www.icloud.com/iclouddrive/0...v7.0.0-stata14
Related Posts with Problem with merging data files into one file
Regression of a few selected observationsI have a set of data but would only require to use of a few observations from the entire dataset. I …
Concordance, sensitivity, specificityHello, I have a very small data set with two diagnostic test data. One is an old test and gold stan…
Urgent: Multilevel moderated mediationI need to estimate a multilevel moderated mediation model, but I can't find the right code for it. I…
Meta proportionHi to everybody... after running the "metaprop" command if it is possible to write instead of "ES" "…
LoopHello fellow Stata users, I have a question regarding the forvalues loop, this is the first time I …
Subscribe to:
Post Comments (Atom)
0 Response to Problem with merging data files into one file
Post a Comment