pasterintelli.blogg.se

Stata merge
Stata merge





stata merge
  1. Stata merge how to#
  2. Stata merge install#
  3. Stata merge code#

Replace Visitor = 1 if DateEntrance <= DateVisit & DateVisit <= DateExitĬollapse (sum) countVisits = Visitor, by(ID Name DateEntrance DateExit)īy ID Name (DateVisit), sort : gen VisitNumber = _n * VisitorĬollapse (sum) Visitor, by(ID Name DateEntrance DateExit DateVisit VisitNumber) Joinby ID using `Visits', unmatched(both) * Create pairwise combinations within ID using -joinby- */

Stata merge how to#

See now here for how to fill in the missingsĪnother approach uses joinby: /* Set up Visits Data */ Reshape long Date, i(ID T) j(Event) string Gen DateEntrance = daily(Entrance, "MDY") | 4 Facility 2 07mar2007 19apr2010 0 |Īny kind of merge seems unhelpful and inappropriate here as you can only match on identifiers. | id Entrance Exit Name datein dateout visit_~t |ġ.

stata merge

Keep id Entrance Exit Name datein dateout visit_count You can then, if desired, revert to the original observations using: by id datein: keep if _n = 1

Stata merge code#

To create the two dataset, we can copy and paste the following code to Stata do editor and run it. dataex- will save you time it is easier and quicker than typing out tables. Either way, run -help dataex- to read the simple instructions for using it.

Stata merge install#

If not, run -ssc install dataex- to get it. | 1 Facility 1 22jul2009 24feb2010 21aug2009 3 |Ģ. We shall merge the datamemory into datafile using variable name as the merging criterion. 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. | id Entrance Exit Name datein dateout visit nvisit visit_~t | Rangejoin nvisit datein dateout using "visits.dta", by(id)īysort id datein: egen visit_count = total(!mi(nvisit)) Input byte id str10(Entrance Exit Name) int(datein dateout) All dates have to be numeric so I pre-converted all dates to Stata dates in the examples below. Rangejoin will pair each stay based on its date in and out (the bounds of the desired interval) and the visit date. To install it, type in Stata's Command window: ssc install rangejoin

stata merge

There's a new user-written program called rangejoin on SSC that is tailor-made for this type of problem. I want to merge these two files together on ID# where VisitDate falls in between Entrance Date and Exit Date so that I can see 1. All it has in it is ID and visitation date: +-+-+ The next data set shows the dates when they were visited. |ID#|Entrance Date| Exit Date | Facility Name | One is the length of stay a person is in a facility, including the facility name. I realize that there is a Stata forum with this exact title, but I did not find its syntax all that helpful, especially since my datasets are a bit different.







Stata merge