Stata The Stata listserver
[Date Prev][Date Next][Thread Prev][Thread Next][Date index][Thread index]

st: RE: how to create groups


From   "Jiang, Tao" <[email protected]>
To   "'[email protected]'" <[email protected]>
Subject   st: RE: how to create groups
Date   Tue, 24 Sep 2002 12:24:55 -0400

If the var. names are g and o, then do:

gen str10 group = g if substr(trim(upper(g)),1,5)=="GROUP"
gen str10 subgroup = "Subgroup1" if group != ""
replace group = group[_n-1] if group==""
replace subgroup = g if substr(trim(upper(g)),1,5)=="SUBGR"
replace subgroup = subgroup[_n-1] if subgroup==""

-----Original Message-----
From: Radu Ban [mailto:[email protected]]
Sent: Tuesday, September 24, 2002 11:51 AM
To: [email protected]
Subject: st: how to create groups


I translated an excel dataset into Stata and now it looks like this

Group1        obs1
Subgroup1    obs2
<blank>        obs3
<blank>        obs4
  .........        .........
<blank>       obsn1
Group1        obs1
Subgroup2    obs2
<blank>        obs3
...............    ........                   
 <blank>     obsn2
............................
Groupk        obs1
Subgroupl    obs2
<blank>       obs3
                    .....
<blank>       obsns

I would like to transform this into:
Group1 Subgroup1         obs1
Group1 Subgroup1         obs2
.......... ..................
Group1 Subgroup2        obs
Group1 Subgroup2        obs
..........
Group1 Subgroup_n        obs
Group2 Subgroup_n+1    obs
Group2 Subgroup_n+1    obs
..............................


I know I could just do the changes in excel by copying and dragging
but I would like to learn how to do it in Stata.

Thanks so much,

Radu Ban



*
*   For searches and help try:
*   http://www.stata.com/support/faqs/res/findit.html
*   http://www.stata.com/support/statalist/faq
*   http://www.ats.ucla.edu/stat/stata/
*
*   For searches and help try:
*   http://www.stata.com/support/faqs/res/findit.html
*   http://www.stata.com/support/statalist/faq
*   http://www.ats.ucla.edu/stat/stata/



© Copyright 1996–2024 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   What's new   |   Site index