Notice: On April 23, 2014, Statalist moved from an email list to a forum, based at statalist.org.
From | "Mike Kim" <kalisperos@gmail.com> |
To | <statalist@hsphsun2.harvard.edu> |
Subject | RE: st: Spliting a variable: Reposting |
Date | Thu, 8 Dec 2011 10:06:47 -0600 |
Hi Matt, This works great. I really appreciate! Mike. -----Original Message----- From: owner-statalist@hsphsun2.harvard.edu [mailto:owner-statalist@hsphsun2.harvard.edu] On Behalf Of Matthew White Sent: Thursday, December 08, 2011 12:56 AM To: statalist@hsphsun2.harvard.edu Subject: Re: st: Spliting a variable: Reposting Hi Mike, This might not be the best way to do it, but here's one attempt: ***BEGIN*** clear input str244 author str244 school "Aguin, H; Ju, H; Gottfred, RK" "[Aguin, H; Ju, H; Gottfred, RK] Indiana U" "Bell, T" "Drexel U" "Buck, MR; Novice, MM; Robert, F; Hump, JH" "[Buck, MR] U Oklahoma; [Novice, MM; Robert, F] U Mississippi; [Hump, JH] Texas U" "Kohli, C; Juri, R" "[Kohli, C] Calif U; [Juri, R] Kansas U" end compress split author, parse("; ") drop author reshape long author, i(school) drop _j drop if missing(author) split school, parse("; [") drop school reshape long school, i(author) drop _j drop if missing(school) replace school = substr(school, 2, .) if substr(school, 1, 1) == "[" gen collaborator = substr(school, 1, strpos(school, "]") - 1) replace collaborator = author if missing(collaborator) replace school = substr(school, strpos(school, "]") + 2, .) if strpos(school, "]") split collaborator, parse("; ") drop collaborator reshape long collaborator, i(author school) drop _j keep if author == collaborator drop collaborator ***END*** Best, Matt On Wed, Dec 7, 2011 at 6:35 PM, Mike Kim <kalisperos@gmail.com> wrote: > Sorry, again. My data structure in the previous posting seems all broken. > > I have a question about splitting a variable. My data look like this: > > clear > input str40 author str80 school > "Aguin, H; Ju, H; Gottfred, RK" "[Aguin, H; Ju, H; Gottfred, RK] Indiana U" > "Bell, T" "Drexel U" > "Buck, MR; Novice, MM; Robert, F; Hump, JH" "[Buck, MR] U Oklahoma; > [Novice, MM; Robert, F] U Mississippi; [Hump, JH] Texas U" > "Kohli, C; Juri, R" "[Kohli, C] Calif U; [Juri, R] Kansas U" > end > > I would like to change into the following form. I tried the following, but > it is not easy to change into this form. Can anyone please help? > split school, p(";" "]") > > clear > input str30 author str30 school > "Aguin, H" "Indiana U" > "Ju,H" "Indiana U" > "Gottfred, RK" "Indiana U" > "Bell, T" "Drexel U" > "Buck, MR" "U Oklahoma" > "Novice, MM" "U Mississippi" > "Robert, F" "U Mississippi" > "Hump, JH" "Texas U" > "Kohli, C" "Calif U" > "Juri, R" "Kansas U" > end > > Thanks in advance. > Mike. > > > * > * 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/ -- Matthew White Data Coordinator Innovations for Poverty Action 101 Whitney Avenue, New Haven, CT 06510 USA +1 434-305-9861 www.poverty-action.org * * 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/