Notice: On March 31, it was announced that Statalist is moving from an email list to a forum. The old list will shut down on April 23, and its replacement, statalist.org is already up and running.

# Re: st: RE: generate

 From Mirriam Gee To statalist@hsphsun2.harvard.edu Subject Re: st: RE: generate Date Wed, 31 Mar 2010 10:38:44 +0200

```Thanks Martin, Sorry for my previous email it just sent in error.  I
Guess my question was not clearer enough. What i want in short is to
create  20 new variables which are equal to the first observation for
each variable. Since i now have the rest of the calculations
Obs                         CC1               CC2                CC3
............................................................CC20
1                              333                440
2                              333                440
3                              333                440
4                              605                777
5                              605                777
6                              605                777
7
..
..
>
> Now i want to cteate new variables which are equal to the first value of each variable for all observations
> Obs                           CCC1               CCC2........................................................................
> 1                                333                  440
> 2                                333                  440
> 3                                333                 440
> 4                                333                  440
> 5                                333                  440
> 6                                333                   440
>

Regards
Mirriam
> O4n Wed, Mar 31, 2010 at 12:03 AM, Martin Weiss <martin.weiss1@gmx.de> wrote:
>
>> " As a next step i now want to create a new variable which only uses
>> mean of the lowest decile  for all variables e.g CCC`i'= mean of
>> decile 1  for all observations."
>>
>>
>>
>> *******
>> vers 9.2
>>
>> clear
>> set obs 10000
>>
>> gen Dy= rchi2(2)
>> xtile deciles = Dy, n(10)
>> forv i=1/20{
>>        gen C`i'=rnormal()
>>        bys deciles: egen CC`i' =mean(C`i')
>> }
>>
>> //Put first observation into new CCCs
>> forv i=1/20{
>>  gen CCC`i' =CC`i'[1]
>> }
>> *******
>>
>>
>> HTH
>> Martin
>>
>> -----Original Message-----
>> From: owner-statalist@hsphsun2.harvard.edu [mailto:owner-statalist@hsphsun2.harvard.edu] On Behalf Of Mirriam Gee
>> Sent: Dienstag, 30. März 2010 23:16
>> To: statalist@hsphsun2.harvard.edu
>> Subject: st: generate
>>
>> Hallo everyone, I am new in stata. I am using STATA 9.2. I do have a
>> very basic statement on how to generate a variable which is equal to
>> the lowest 10th percentile of income(Dy) ?
>> I tried this:
>> sort Dy
>> Xtile deciles = Dy, n(10)
>> forvalues `i' = 1/20 {
>> bys deciles : egen CC`i' =mean (C`i' )
>> }
>>  This seem to do part of the job. But it gives me mean of all deciles.
>> For example CC1 varies from decile 1-10 as follows:
>> Deciles                    CC1               CC2
>> CC3..............................................
>> 1                              333                440
>> 1                              333                440
>> 1                              333                440
>> 2                              605                777
>> 2                              605                777
>> 2                              605                777
>> 2
>> ..
>> ..
>>
>> As a next step i now want to create a new variable which only uses
>> mean of the lowest decile  for all variables e.g CCC`i'= mean of
>> decile 1  for all observations. To be more precise i want CCC1 to be
>> equl to 333 for all observation, and CCC2 to be 440 etc I know i can
>> do this manually by checking value of CC`i'  when decile=1 , and then
>> proceed to input values:
>>
>>                                  generate CCC1 = 330
>>
>>
>>                             generate CCC2=  440
>>
>>
>>                                    .         .
>>
>>
>>                                    .         .
>>
>>
>>                               etc up to 20th item.
>> I was just wondering if there is a way of doing it automatically in my
>> do file without stoping and checking results and inputting them
>> manually, because i do have a lot of variables, even more than 20?
>>
>>
>> Mirriam
>>
>> *
>> *   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/
>>
>

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