Statalist The Stata Listserver

[Date Prev][Date Next][Thread Prev][Thread Next][Date index][Thread index]

Re: st: Merge Question

From   "Dimitriy V. Masterov" <[email protected]>
To   [email protected]
Subject   Re: st: Merge Question
Date   Fri, 1 Sep 2006 23:45:16 -0400


It's hard to give advice without exactly knowing what your data sets
look like, but I would

(1) transform your WB data like I do with the fake data below, save it
as new_data.dta and clear
(3) Open first_data.dta and sort by country and year
(4) merge using country year using C:/.../new_data.dta

Here's the code to inspire step 1:

/* Make Fake Data */
set obs 10
gen year=2000+_n

foreach country in Atlantis Tuvalu Abusrdistan Paradiseland {
	gen `country'=uniform()

/* Rename Each Country as x1,... */
local i=1
foreach country in Atlantis Tuvalu Abusrdistan Paradiseland {
	rename `country' x`i'
	local n`i' "`country'"
	local i=`i'+1

/* Reshape Data */
reshape long x, i(year) j(country)

/* Label The Countries */
qui sum country
forvalues j=`r(min)'/`r(max)' {
	label define countrylbl `j' "`n`j''", modify
lab val country countrylbl

sort country year
*   For searches and help try:

© Copyright 1996–2024 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   What's new   |   Site index