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
Standard deviation lines for xtline graphI am wondering how to add standard deviation lines to a timeseries graph I made (xtline) I calculat…
Multicollinearity after variable transformation & impact on R^2Hello, I am running a simple linear regression model and I found that 3 of my variables (ssr1 ssr2 …
After estimation, how can I obtain predictions at the mean of some of the covariates?I know that after estimation if I replace some of the covariates with their means and predict, I can…
Keep with conditionHey guys, I want to keep only the observations which are untimely by the employee and at the same ti…
Graphing Interaction of Time-Varying Covariate and Dummy Variable in a Growth Curve Model using MIxedGreetings. I have a longitudinal data set (set up in long form), and I am trying to graph a signific…
Subscribe to:
Post Comments (Atom)
0 Response to Creating panel dataset
Post a Comment