Bookmark and Share

Notice: On April 23, 2014, Statalist moved from an email list to a forum, based at statalist.org.


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

RE: st: Spliting a variable: Reposting


From   "Mike Kim" <[email protected]>
To   <[email protected]>
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: [email protected]
[mailto:[email protected]] On Behalf Of Matthew White
Sent: Thursday, December 08, 2011 12:56 AM
To: [email protected]
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 <[email protected]> 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/


© Copyright 1996–2018 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   Site index