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]

st: RE: grouping variables within individuals


From   "Martin Weiss" <[email protected]>
To   <[email protected]>
Subject   st: RE: grouping variables within individuals
Date   Mon, 30 Aug 2010 19:48:26 +0200

<>

The basic technique is shown here. See NJC´s
http://www.stata-journal.com/sjpdf.html?articlenum=pr0004


***********
clear*

   // :mylabel , auto // str10 double byte
input int id str10 term   byte(class  grade)
475        "Spr 05"    4              4
475        "Spr 05"    7              0
475        "Fall 05"    7              0
475        "Fall 05"    7              0
475        "Spr 06 "    .              2
475        "Spr 06 "    .              0
475        "Spr 06 "    .              0
475        "Fall 06"    .               3
475        "Fall 06"    .               0
476        "Fall 05"    5              4
476        "Fall 05"    6              4
476        "Fall 05"    3              4
476        "Fall 05"    2              4
476        "Fall 05"    1              -1
476        "Fall 05"    4              4
476        "Spr 06 "    .              1
476        "Spr 06 "    .              4
476        "Spr 06 "    .              4
476        "Sum 06 "    .           3
476        "Sum 06 "    .           -3
476        "Fall 06"    .               3
476        "Fall 06"    .               3
476        "Fall 06"    .               4
476        "Fall 06"    .               4
476        "Fall 06"    .               4
477        "Fall 05"    6              4
477        "Fall 05"    2              4
477        "Fall 05"    5              4
477        "Fall 05"    3              4
477        "Fall 05"    4              4
477        "Fall 05"    1              -1
477        "Spr 06 "     .              4
477        "Spr 06 "     .              0
477        "Spr 06 "     .              0
477        "Spr 06 "     .              2
477        "Sum 06 "     .           4
477        "Fall 06"     .               0
477        "Fall 06"     .               2
477        "Fall 06"     .               0
477        "Spr 07 "     .              3
477        "Spr 07 "     .              0
477        "Spr 07 "     .              0
477        "Fall 07"     .               3
477        "Fall 07"     .               2
477        "Fall 07"     .               3
477        "Spr 08 "     .              2
477        "Spr 08 "     .              3
477        "Spr 08 "     .              4
477        "Spr 08 "     .              3
end


replace term=trim(term)
compress
list, noobs  sepby(id)

bysort id term: gen byte new=_n==1
by id:gen termvar=sum(new)
l, sepby(id term) noo
***********

You have to let Stata know the ordering of the terms, though...


HTH
Martin


-----Original Message-----
From: [email protected]
[mailto:[email protected]] On Behalf Of Devora Shamah
Sent: Montag, 30. August 2010 19:37
To: [email protected]
Subject: st: grouping variables within individuals

I am working with a dataset that contains grade records for students over
several terms. Each student has 1-6 classes per term. I need to assign each
term a "count of term" so I can create variables that capture the total
number of classes taken during the students' first and second term and the
percent of classes they have passed. The students all started at different
terms and not all of them took classes in consecutive terms. I have easily
identified the first term by using the row minimum command in stata. I am
struggling to find an efficient and accurate way to identify the second
term. I would appreciate any thoughts anyone has.

My data looks like this (in long form) The class values refer to type of
class, and grades range from withdraws through A's.  Essentially I need a
way to identify that for student 475, Spring 05 was his first term, and Fall
)5 was his second term, for student 476 Fall 05 was his first term and
Spring 05 was his second term and so on. 

id            term      class       grade
475         Spr 05    4              4
475         Spr 05    2              2
475         Spr 05    5              3
475         Spr 05    3              2
475         Spr 05    1              -1
475         Spr 05    6              3
475         Fall 05    7              0
475         Fall 05    7              0
475         Fall 05    7              0
475         Spr 06                    2
475         Spr 06                    0
475         Spr 06                    0
475         Fall 06                    3
475         Fall 06                    0
476         Fall 05    5              4
476         Fall 05    6              4
476         Fall 05    3              4
476         Fall 05    2              4
476         Fall 05    1              -1
476         Fall 05    4              4
476         Spr 06                    1
476         Spr 06                    4
476         Spr 06                    4
476         Sum 06                 3
476         Sum 06                 -3
476         Fall 06                    3
476         Fall 06                    3
476         Fall 06                    4
476         Fall 06                    4
476         Fall 06                    4
477         Fall 05    6              4
477         Fall 05    2              4
477         Fall 05    5              4
477         Fall 05    3              4
477         Fall 05    4              4
477         Fall 05    1              -1
477         Spr 06                    4
477         Spr 06                    0
477         Spr 06                    0
477         Spr 06                    2
477         Sum 06                 4
477         Fall 06                    0
477         Fall 06                    2
477         Fall 06                    0
477         Spr 07                    3
477         Spr 07                    0
477         Spr 07                    0
477         Fall 07                    3
477         Fall 07                    2
477         Fall 07                    3
477         Spr 08                    2
477         Spr 08                    3
477         Spr 08                    4
477         Spr 08                    3






Devora Shamah
Manager, Research and Reporting

Gateway to College National Network
529 SE Grand Ave. #300
Portland, OR 97214
phone: 971.634.1203
fax: 971.634.1213
www.gatewaytocollege.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