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
Testing some stuff Code: sysuse nlsw88,clear reg married i.collgrad##c.wage margins collgrad, at(wage== (5 10 15)) po…
Having Two Margin Plots on One GraphHi everyone. I am struggling with a presentation issue. I have run a probit regression and I am coll…
Linear probability models with interactions: how can I calculate relative effects / relative risk ratios?Dear Statalisters, I am running Linear Probability Models with interactions and would like to calcu…
Row MedianHello, I have daily panel data over several years and for several stocks. For each day and for each…
Large variances in probit regressionHi, I encountered the following problem when running IVPROBIT: the regressors include a few dummy v…
Subscribe to:
Post Comments (Atom)
0 Response to Creating panel dataset
Post a Comment