I would like to create a long panel from the 17 waves of panel data from the HILDA survey but am struggling with two key issues:
(1) code to append the 17 waves, and
(2) dealing with the variable names, which include a prefix letter representing the number wave, e.g. ahgage - age in wave 1, bhgage - age in wave 2, chgage - age in wave 3, hence prefix 'a' = 1, 'b' = 2, etc. In this case, I believe I can use rename group (?) to remove the wave reference, but not sure of the exact code, and secondly, would I do so while appending the waves?
Most of the variables are in all waves (such as age, gender, education, wages), however there are three (categorical) variables only in waves 4, 7, 10 , 14 (hence the separate append).
My code for appending the waves follows:
clear
set memory 1g
set more off
use "C:\data\Combined_a170c.dta" // original data file
keep xwaveid ahgsex ahgage aeduc awage
tempfile master
save "`master'", replace // save to temp data file
// add in data from other waves (in and not in wave 1)
* Cleaning data for waves 2 to 17 // (excl waves 4, 7, 10, 14 as these include specific data not in other waves)
local wave b c e f h i k l m o p q
foreach x of local wave {
use "C:\data\Combined_`x'170c.dta", clear
keep xwaveid `x'hgsex `x'hgage `x'educ `x'wage
save "`master'", replace
use "C:\data\Hilda\Combined_`x'170c.dta", clear
append using "`master'"
save "C:\data\basedata.dta", replace // new data file
}
* Cleaning data for waves 4, 7, 10, 14
local wave2 d g j n // (waves 4, 7, 10, 14)
foreach y of local wave2 {
use "C:\data\Combined_`y'170c.dta", clear
keep xwaveid `y'hgsex `y'hgage `y'educ `y'wage `y'reltype `y'relimp `y'relat //
save "`master'", replace
use "C:\data\Combined_`y'170c.dta", clear
append using "`master'"
save "C:\data\basedata.dta", replace
}
//
Stata responded with "invalid file specification"
r(198);
Your kind assistance is appreciated as always.
Related Posts with To append or to merge
l2.X variable as IV for X? Anderson Hsiao(1981). how to test for endogeneity panel (2sls)Hi, I'm a student and I'm trying to determine a model to use for my dataset. The goal is to estimate…
Suggestions for statistical tests to run on variables before OLS regression?Hi guys, Im a beginner user, i have a short project that i need some help on. I have an OLS regress…
Dividing series of variables through loopingHi, I have variables Jan_13 to Mar_21, referring to months January 2013 to March 2021. I need to cre…
Validity and Robustness checks for Pooled/Repeated Cross-Sectional DataHi, I am trying to identify the impact of race on unemployment (due to COVID-19) from April to Decem…
Is my use of a t-test with this data appropriate?Hallo Apologies for not using dataex. I have tried and failed to install it (I used ssc install dat…
Subscribe to:
Post Comments (Atom)
0 Response to To append or to merge
Post a Comment