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

Re: st: Generating variabels - clarification


From   Edwin Leuven <[email protected]>
To   [email protected]
Subject   Re: st: Generating variabels - clarification
Date   Thu, 27 Mar 2003 12:33:48 +0100

try

expand Count

On Mon Mar 24 2003 15:28, Alexander wrote:
> Hi,
>
> I posted a problem earlier on this:
> Can anyone help me with this problem?
> I have two variabels:
>
> Price                Count
> 20.0                  100
> 21.0                  200
> 22.0                  300
>
> I would like to make one new variabel that gives f. ex price=20 hundred
> registrations, then 21 � 200 registrations
>
> Ex
>
> New variable
> 20
> 20
> 20
> etc --> hundred times (as given by countvariabel)
> 21
> 21
> 21
> 21
> etc � 200 times
> 22
> 22
> 22
> etc � 300 times
>
> Laurel Copeland solved this for me with (thanks!):
>
> set obs 600
> gen price=20.0
> replace price=21.0 if _n>100
> replace price=22.0 if _n>300
>
> This works out fine, however, my datafile have thousand of different
> prices, eg. 20.1, 20.12,20.56 etc. and the count variabels is different
> values for each of the prices. I am looking for a way to make syntax
> that generated a new variabel like the one above, but without having to
> write in the prices and counts.
>
> -foreach- or maybe -forvalues- can solve this, but I am not sure how?
>
> Any help would be greatly appreciated!
>
> Best regards,
> Alexander Severinsen
>
>
>
> *
> *   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/

-- 
Edwin Leuven
Department of Economics
University of Amsterdam
Phone: +31 (0)20 525 5241
Fax: +31 (0)20 525 4310
http://www1.fee.uva.nl/scholar/mdw/leuven

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