Statalist The Stata Listserver


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

st: Data Manipulation--is the merge command appropriate?


From   "Asiedu, Elizabeth" <[email protected]>
To   <[email protected]>
Subject   st: Data Manipulation--is the merge command appropriate?
Date   Mon, 25 Sep 2006 10:12:47 -0500

I have an unbalanced panel dataset. I'd like to convert to a balanced panel dataset where the data for the missing years are zero. How do I do this in Stata? I'll use an example to illustrate my problem.

 

 

Dataset 1

Country id        year                  foreign aid

1                      1993                230

1                      1994                130

2                      1990                100

2                      1994                120      

 

There are 2 countries. Country 1 did not receive any aid for 1990,1991, and 1992. Country 2 did not receive aid for 1991, 1992 and 1993. I'd like each country to have data from 1990-1994, and for foreign aid=0 for the missing years. 

 

 

The dataset I need for my analysis should look like

 

Dataset 2

Country id        year                  foreign aid

1                      1990                0

1                      1991                0

1                      1992                0

1                      1993                230

1                      1994                130

2                      1990                100

2                      1991                0

2                      1992                0

2                      1993                0

2                      1994                120

 

 

This is what I tried. 

Step 1: I created another dataset with only two columns; country id and year:

 

Dataset 3

Country id        year                  

1                      1990                

1                      1991                

1                      1992                

1                      1993                

1                      1994                

2                      1990                

2                      1991                

2                      1992                

2                      1993                

2                      1994                

 

Step 2: I merged the two datasets (i.e., Dataset 1 and Dataset 3) using country id and year.

 

I thought the merge will generate a balanced panel with "null" values for the variable foreign aid, for the years for which the country did not receive any aid. I could then replace the "null" with zeros. However the merge did not produce the desired result-it just did not work.  

 

Any suggestions? Is the merge command appropriate?

 

Thanks in advance.

 

Elizabeth Asiedu


*
*   For searches and help try:
*   http://www.stata.com/support/faqs/res/findit.html
*   http://www.stata.com/support/statalist/faq
*   http://www.ats.ucla.edu/stat/stata/



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