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: reshaping data
From
Paul Byatta <[email protected]>
To
"[email protected]" <[email protected]>
Subject
Re: st: reshaping data
Date
Wed, 27 Nov 2013 07:07:07 -0800 (PST)
Hi Scott,
Thank you. Your illustration worked well.
Paul
On Wednesday, November 27, 2013 4:42 PM, Scott Merryman <[email protected]> wrote:
-reshape- is what you need:
clear
input pupid_1 str4 name_1 age_1 str4 sch_1 pupid_2 str4 name_2 age_2
str4 str4 sch_2 pupid_3 str4 name_3 age_3 str4 sch_3
231 Jay 13 DA 232 Ren 12 SP 233 Mimi 14 HH
end
gen id = _n
reshape long pupid name age sch, i(id) string
drop id _j
l
Scott
On Wed, Nov 27, 2013 at 5:47 AM, Paul Byatta <[email protected]> wrote:
> Hi Statalist,
>
>
> I have a dataset in which an exact set of questions is asked about multiple pupils, hence the data reported looks like this in Stata. For illustration, the data is from 3 pupils.
>
>
> pupid_1 name_1 age_1 sch_1 pupid_2 name_2 age_2 sch_2 pupid_3 name_3 age_3 sch_3
> 231 Jay 13 DA 232 Ren 12 SP 233 Mimi 14 HH
>
> I am wondering is there a short way I could turn the data from the current wide format (where everything appears on the same row) to a long format (where each pupil information will appear on its own row) that will look like below?
>
> pupid name age sch
> 231 Jay 13 DA
> 232 Ren 12 SP
> 233 Mimi 14 HH
>
> I have looked at -reshape- command and it doesnt seem to allow me retain the core of the variable name, ie drop the "_#" part of variable names above and retain the main part.
>
>
> Thanks for the help
>
> Paul
>
*
* For searches and help try:
* http://www.stata.com/help.cgi?search
* http://www.stata.com/support/faqs/resources/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/faqs/resources/statalist-faq/
* http://www.ats.ucla.edu/stat/stata/