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
Issues with attempts to drop observations (r109 type mismatch error)Hi there, I'm new to Stata and attempting to drop some observations from my sample, however I keep …
Drop variables with common suffix under certain conditionsDear all, I am facing difficulties in dropping some variables conditional on the missing observatio…
Fractional Proportional Models and Controlling for Time.Hi Statalist, I have a dataset with a large number of observations and a small T. The years for my d…
Long local macro with line breaksHi I have this long code: local varlist1 "AMAZONAS ANCASH APURIMAC AREQUIPA AYACUCHO CAJAMARCA CALLA…
Oaxaca help - mean wage generated does not match the one given by sum commandGood afternoon, I am using the oaxaca command to decompose the ethnic pay gap, in the example here …
Subscribe to:
Post Comments (Atom)
0 Response to To append or to merge
Post a Comment