

Missing values in uid may be the reason Stata does not believe this variable works well.I think Stata promotes variables to the more accurate format when it needs to, say when you replace an integer-valued variable with non-integer values same thing should happen with merge when you have say byte values in one data set, and you merge in float values on the same variable from the other data set.Type describe uid to find out what the current format is, and may be format uid %12.0f to get rid of the scientific notation. On top of Nick Cox' answer concerning data types, the issue may simply be formatting.If uid passes the check in both files, it should still do so in the merged file it must be failing in at least one of the source files in order to fail in the merged file. Stata would complain if uid is not a unique identifier when performing merge, anyway, but that's a useful check on its own. To check whether your variable really identifies observations, type isid uid.Now I finally got it to work by just starting over and not recasting the uid variable as a string in the first place, but I'm still at a loss as to why my previous efforts did not work, or how the merge command actually decided to change my values. I noticed that the value it was changing all of my observations to was the last value in the dataset.Ĥ) Just because I was tweaking around, I recast the uid variable as double, and was getting the same results. It was with this that I was unable to do the initial merge. To join corresponding observations from a Stata dataset with those in the dataset in memory, type: merge 1:1 varlist using filename. So Nick's advice helped, thanks! This is what I was doing that went wrong, so I wonder if someone could point out why it didn't work.ġ) I created the uid variable in each dataset by concatenating two numeric variables, which cast the uid variable as a string.Ģ) I ran destring on the whole dataset (because there were a lot of incorrectly cast variables), which turned uid into a double.ģ) Then I recast uid as a string. 2.50101e+10Īny help would be very appreciated.I'm sure there's a simple answer but it's eluding me at the moment. (38 observations deleted) THen we can drop the merge variable itself. 25010201īut then once I try to run the merge, it changes all of my values, so that I see. Know I am looking to merge rounds roster files and I need to use data of children whos data is. What I realized it happening is that when I open FranceSQ, everything is normal, and when I look at my uid variable, I have the following values. I have merged my variables with roster files of both rounds. Now what's confusing me is that it tells me that uid doesn't uniquely identify my observations. First, its important to clear up the terminology.
Merge stata manual#
Merge 1:1 uid using FranceHQ, gen(_merge) keep(match) 1 Answer Sorted by: 2 In case the Stata manual is unclear, heres a quick overview. They both have a variable that I created named "uid" that uniquely identifies the observations.
Merge stata code#
Stata now supports executing Python code in a very clean and unobtrusive way. I am trying to merge two datasets in Stata, FranceSQ.dta and FranceHQ.dta. 2 Issues 2 List Boards Service Desk Milestones Merge requests 0 Merge. When showing example data, always use the dataex command.I feel like I'm missing something really basic here.

The data files must have only one record per participant in. When asking for help with code, always show example data. This support document is designed to assist data users with merging two data files using Stata. It also makes it possible for those who want to help you to create a faithful representation of your example to try out their code, which in turn makes it more likely that their answer will actually work in your data. Merging two datasets require that both have at least one variable in common (either string or numeric). It includes complete information about aspects of the data that are often critical to answering your question but cannot be seen from tabular displays or screenshots. 1.0) Oscar Torres-Reyna Intro Merge adds variables to a dataset. dataex will save you time it is easier and quicker than typing out tables. Either way, run help dataex and read the simple instructions for using it.
Merge stata install#
If not, run ssc install dataex to get it. If you are running version 17, 16 or a fully updated version 15.1 or 14.2, dataex is already part of your official Stata installation. In order to get a helpful response, you need to show some example data.īe sure to use the dataex command to do this. There are many ways your data might be organized that are consistent with your description, and each would require a somewhat different approach.


Even the best descriptions of data are no substitute for an actual example of the data. Descriptions of data are well-meant but insufficient to help those who want to help you.
