Bookmark and Share

Notice: On April 23, 2014, Statalist moved from an email list to a forum, based at

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

st: Generating duplicate variables when merging by varname

From   Ludovico Zaraga <>
To   statalist <>
Subject   st: Generating duplicate variables when merging by varname
Date   Tue, 25 Feb 2014 10:26:47 -0600


I have one dataset (the master dataset) with a list of countries,
product names and years. I then have another dataset with price
indices over all countries in a given year. The latter dataset does
not contain countries since it contains an index summarizing all
country information. Suppose I have N countries.

I would like to merge these two datasets in the following way. For
each product (in a given year) in the master dataset, I want to create
N variables (one for each country), all of which contain the price
index for that product (in a given year). These variables would have
the price index from the second dataset in correspondence to only one
country-product pair (for all the years in the dataset), and missing
values in correspondece to all other countries and products.

Is there a simple way to do this with a merge command, specifying some
"by" option? Or would I have to do this using foreach loops?


*   For searches and help try:

© Copyright 1996–2018 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   Site index