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   <theodroe@bellsouth.net>
To   <statalist@hsphsun2.harvard.edu>
Subject   RE: st: Merge Files one to many
Date   Sun, 1 Apr 2012 09:13:59 -0400

Eric -

Thanks for the reply, yes I am using 12.

Ted

-----Original Message-----
From: owner-statalist@hsphsun2.harvard.edu
[mailto:owner-statalist@hsphsun2.harvard.edu] On Behalf Of Eric Booth
Sent: Saturday, March 31, 2012 8:31 PM
To: statalist@hsphsun2.harvard.edu
Subject: Re: st: Merge Files one to many

<>


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/

*
*   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