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
trouble with variable list in egen using macros from loopsHi Folks- The issue I'm having is that when I have a variable list after egen, and the variable lis…
Problem generating a new variable based on previous valuesHi all, I'm trying to generate a variable (steponecpn) so that is represents the change in Cumulati…
Help with replace and egenHi everyone, I have the dataset below. How can i replace the S3_Q10K with value in S1C_Q0_*? For ex…
Propensity scores for multi-valued treatmentI would like to estimate the impact of medium and heavy flooding (compared to noflood) on post-flood…
How to merge CRSP daily with CRSP/Compustat Merged Annually data?Hello, I would like to ask how to merge CRSP Daily data with CRSP/Compustat Merged Annually data? I…
Subscribe to:
Post Comments (Atom)
0 Response to Creating panel dataset
Post a Comment