Notice: On April 23, 2014, Statalist moved from an email list to a forum, based at statalist.org.
From | Ludovico Zaraga <ludovico.zaraga@gmail.com> |
To | statalist <statalist@hsphsun2.harvard.edu> |
Subject | st: Generating duplicate variables when merging by varname |
Date | Tue, 25 Feb 2014 10:26:47 -0600 |
Hello, 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? Thanks, Ludovico * * For searches and help try: * http://www.stata.com/help.cgi?search * http://www.stata.com/support/faqs/resources/statalist-faq/ * http://www.ats.ucla.edu/stat/stata/