Hello
I am trying to create a panel dataset using Waves 1 to 5 from the South African National Income Dynamics Survey (NIDS).
The code that i have already created it set up as follows:
I first define my data directories.
At a cross-sectional level, i believe that it would first require me to append the individual level datasets and then to merge in the household level dataset.
Then I would go on to simply merge in the five waves of data. I have used loops and globals to do this.
I thought it would be fairly simple, however, i am getting an error saying: unable to change to dir/data/NIDS/Wave 1
This stops me from proceeding forward.
The code looks like:
* Define Directory
global dir "C:\Users\Sophie\Documents\2019 first semester\Thesis\Section 2_Stata\Main Thesis"
global datadir "$dir/data/"
global resultsdir "$dir/results/"
global logdir "$dir/log/"
global NIDSdir "dir/data/NIDS"
* Create log file
cap log close
*----------------------------------------------------------
// MERGING //
di "MERGING"
di "$S_DATE"
** Define the different version numbers for each wave
global VersionIN1 "Anon_V7.0.0"
global VersionIN2 "Anon_V4.0.0"
global VersionIN3 "Anon_V3.0.0"
global VersionIN4 "Anon_V2.0.0"
global VersionIN5 "Anon_V1.0.0"
/* Append individual level datasets for each wave: adult, child, proxy */
forvalues i = 1(1)5 {
cd "${NIDSdir}/Wave `i'"
di ""
di "Wave `i'"
di ""
di "Data directory ${NIDSdir}"
di ""
di "Adult_W`i'_${VersionIN`i'}.dta"
// Open Adult File
use "Adult_W`i'_${VersionIN`i'}.dta", clear
// Add Children and Proxy Respondents to the Adult
append using "Child_W`i'_${VersionIN`i'}.dta" "Proxy_W`i'_${VersionIN`i'}.dta"
// Merge Household questionnaire data using hhid
merge m:1 w`i'_hhid using "HHQuestionnaire_W`i'_${VersionIN`i'}.dta"
drop if _merge !=3
drop _merge
// Merge HHderived file
merge m:1 w`i'_hhid using "hhderived_W`i'_${VersionIN`i'}.dta"
drop if _merge !=3
drop _merge
di "wave `i'"
// Merge indderived and HouseholdRoster
merge 1:1 pid using "indderived_W`i'_${VersionIN`i'}.dta"
drop if _merge ! = 3
drop _merge
di "wave `i'"
merge 1:1 pid using "HouseholdRoster_W`i'_${VersionIN`i'}.dta"
drop if _merge ! = 3
drop _merge
di "wave `i'"
numlabel, add
save "${datadir}/wave`i'_merged.dta", replace
}
kind regards
Sophie Gebers
Related Posts with Creating panel dataset
Calculating the turning pointHi, My name is Jan, and I would like to find the turning point for my regression. I looked at previ…
Diff in diff with IV for treatment dummyHi all, For my data analysis, I am estimating a difference-in-difference model of the sort Code: …
Rolling window standard deviation of residuals in ARIMADear Statalist community, I have trouble writing the code and would greatly appreciate your help. …
Delete observations within timespan of each otherDear all, I am writing my Master's Thesis and am currently cleaning my data. For each Company I wan…
marginsplot generating hard-to-read picturesDear All, I am running > marginsplot, recast(scatter) to illustrate margins & CIs and what re…
Subscribe to:
Post Comments (Atom)
0 Response to Creating panel dataset
Post a Comment