How to merge datasets in Stata conditionally?

What are some ways to merge panel data in STATA?

  • Answer:

    I am assuming you are using Stata 11 or 12 or 13 and that you are  conversant with Stata terminologies. No matter what type of data you are  merging (cross section or panel data or time series) you need some type  of identifier variable in both files. The identifier variable (may be  the name of the entities about whom the dataset is) must have the same  name in both files and both datasets must be sorted using this variable.  Once you have ensured that you can simply use the merge command in its  four forms that is either use xyz.dta merge 1:1 id_var using abc.dta or use xyz.dta merge 1:m id_var using def.dta or use xyz.dta merge m:1 id_var using  ghi.dta I have no experience with the m:m merge may be someone else can help with that. If  you want more to the point help, you need to provide some information  about your two datasets.Specifically you need to provide me with the  following information For both datasets -is this panel data? -range of years -what is the variable that stores the names/ids of the entities.

Krishanu Karmakar at Quora Visit the source

Was this solution helpful to you?

Other answers

It is like time-series or cross-sectional data, but usually you will need two ids, one for panel and one for time. it will look like merge 1:1  idcode  year using  xxxx.dta, for detail check "help merge" in Stata. Usually, berfore merge two panel datasets, you may need to shape both into long format, check "help reshape" in Stata. And you can  also merge cs with panel, ts with panel and panel with panel.

Shan Hua

Just Added Q & A:

Find solution

For every problem there is a solution! Proved by Solucija.

  • Got an issue and looking for advice?

  • Ask Solucija to search every corner of the Web for help.

  • Get workable solutions and helpful tips in a moment.

Just ask Solucija about an issue you face and immediately get a list of ready solutions, answers and tips from other Internet users. We always provide the most suitable and complete answer to your question at the top, along with a few good alternatives below.