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

st: Re: RE: expand an agrregated file


From   "Scott Merryman" <[email protected]>
To   <[email protected]>
Subject   st: Re: RE: expand an agrregated file
Date   Wed, 27 Aug 2003 16:59:20 -0500

----- Original Message ----- 
From: "Nick Cox" <[email protected]>
To: <[email protected]>
Sent: Wednesday, August 27, 2003 7:20 AM
Subject: st: RE: expand an agrregated file


> ann fitzmaurice
>
> >  i have a file in the following format
> >
> > region lgd pop_lgd pop_region
> > 1 1 20 65
> > 1 2 45 65
> > 2 1 10 25
> > 2 2 15 25
> >   There are other variables and populations with the
> > variables but this is
> > just a small example
> >
> > i would like to create a data set that is case based so
> > instead of 4 lines
> > in the above example will have 90 lines - i have looked at
> > expand but am
> > not sure if this is the command to use
>
> Yes, it is.
>
> Nick
> [email protected]
>

Ann,

I take it when you say you want 90 observations, you want to expand each region
+ lgd by its population?

If so, one way would be to:

forvalue i = 1/4 {
    local num = pop_lgd[`i']
    expand `num' in `i'
    }


Example:

. l

     +-----------------------------------+
     | region   lgd   pop_lgd   pop_re~n |
     |-----------------------------------|
  1. |      1     1        20         65 |
  2. |      1     2        45         65 |
  3. |      2     1        10         25 |
  4. |      2     2        15         25 |
     +-----------------------------------+

. do "C:\WINDOWS\TEMP\STD01000000.tmp"

.         forvalue i = 1/4 {
  2.                 local num = pop_lgd[`i']
  3.                 expand `num' in `i'
  4.                 }
(19 observations created)
(44 observations created)
(9 observations created)
(14 observations created)

.
end of do-file

. sum

    Variable |       Obs        Mean    Std. Dev.       Min        Max
-------------+--------------------------------------------------------
      region |        90    1.277778    .4504125          1          2
         lgd |        90    1.666667    .4740455          1          2
     pop_lgd |        90    30.55556    14.79152         10         45
  pop_region |        90    53.88889     18.0165         25         65



Hope this helps,
Scott


*
*   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