Bookmark and Share

Notice: On March 31, it was announced that Statalist is moving from an email list to a forum. The old list will shut down on April 23, and its replacement, statalist.org is already up and running.


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

Re: st: Merge Files one to many


From   Eric Booth <eric.a.booth@gmail.com>
To   statalist@hsphsun2.harvard.edu
Subject   Re: st: Merge Files one to many
Date   Sat, 31 Mar 2012 19:31:12 -0500

<>


Since there is one principal observation per school & many teachers per school, you want a many-to-one merge with the teacher dataset in memory (assuming you've got Stata 12 since you didn't state otherwise --  you want to use the m:1 merge type).

That is, if you use the teacher dataset (the first dataset) as the master dataset (in memory) and merge in the principal dataset (the second dataset) as the 'using' dataset, then you'd run something like:

****
use "teacher.dta", clear 

merge m:1  schoolid using "principal.dta"  //include any options here about updating, replacing, or matching values

sa "combined.dta", replace
*check your merge report or run -tabulate _merge-
****

- Eric
__
Eric A. Booth
Public Policy Research Institute 
Texas A&M University
ebooth@ppri.tamu.edu
+979.845.6754




On Mar 31, 2012, at 7:00 PM, <theodroe@bellsouth.net> wrote:

> Have two data sets with common variable. The teacher data set has several
> teachers per school. The school variable is a nominal variable that is
> unique to each school. So if there are 20 teachers in a school the school
> variable is repeated 20 times. The principal data file has one principal per
> school and I want to merge/match on school. There is one principal to each
> school and this file uses the same school variable to identify the school
> the principal is in. What I need to do is to match the principal data to
> every teacher in that school. 
> 
> So the file would look like:
> 
> 
> School	teacher_var1	teacher_var2	principal_var1
> 123		23			45			56	
> 123		25			44			56
> 123		21			43			56
> 123		56			55			56
> 331		21			22			51
> 331		21			29			51
> 331		26			21			51
> 
> Help please
> 		
> 
> *
> *   For searches and help try:
> *   http://www.stata.com/help.cgi?search
> *   http://www.stata.com/support/statalist/faq
> *   http://www.ats.ucla.edu/stat/stata/


*
*   For searches and help try:
*   http://www.stata.com/help.cgi?search
*   http://www.stata.com/support/statalist/faq
*   http://www.ats.ucla.edu/stat/stata/


© Copyright 1996–2014 StataCorp LP   |   Terms of use   |   Privacy   |   Contact us   |   Site index