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]

RE: st: Loop to replace values of a variable


From   "Lachenbruch, Peter" <Peter.Lachenbruch@oregonstate.edu>
To   "statalist@hsphsun2.harvard.edu" <statalist@hsphsun2.harvard.edu>
Subject   RE: st: Loop to replace values of a variable
Date   Wed, 18 Dec 2013 16:27:37 +0000

EVERYBODY!!!  Please note that Buis's name is spelled MAArten  NOT MartEEn.  It is only courteous to spell his name correctly.  I have had a tough name to spell for 76 years and am used to it being screwed up.  But Maarten doesn't deserve to have a simple name mangled.

Peter A. Lachenbruch,
Professor (retired)
________________________________________
From: owner-statalist@hsphsun2.harvard.edu [owner-statalist@hsphsun2.harvard.edu] on behalf of Maarten Buis [maartenlbuis@gmail.com]
Sent: Wednesday, December 18, 2013 5:40 AM
To: statalist@hsphsun2.harvard.edu
Subject: Re: st: Loop to replace values of a variable

no need to loop:

gen x = _n*.1

Hope this helps,
Maarten


On Wed, Dec 18, 2013 at 2:33 PM, emanuele mazzini
<madsoenistata@gmail.com> wrote:
> Dear all statalist users,
>
> I would like to program a (relatively) simple loop to replace the
> values of a variable I created, but I cannot  figure it out how to
> write the syntax.
>
> The structure of my data is very simple:
> I have 300 observations and a variable, say x, that in the first cell
> (i.e. for n=1) is equal to 0.1, while it is missing for all other 299
> cells. Data look like:
>
> n     x
> 1    0.1
> 2     .
> 3     .
> 4     .
> .
> .
> .
> .
> .
> 299  .
> 300  .
>
> I would like the loop to replace the missing values of my variable by
> going from cell 2 to cell 300, and to have a replace that would be at
> a 0.1 intervals, so as to obtain data that look like:
>
> n     x
> 1    0.1
> 2    0.2
> 3    0.3
> 4    0.4
> .
> .
> .
> .
> .
> 299  29.9
> 300  30
>
> I can obviously do it by hand, but a loop would be naturally much more
> efficient!
> Does anyone know how to make it?
>
> Thank you in advance.
> *
> *   For searches and help try:
> *   http://www.stata.com/help.cgi?search
> *   http://www.stata.com/support/faqs/resources/statalist-faq/
> *   http://www.ats.ucla.edu/stat/stata/



--
---------------------------------
Maarten L. Buis
WZB
Reichpietschufer 50
10785 Berlin
Germany

http://www.maartenbuis.nl
---------------------------------
*
*   For searches and help try:
*   http://www.stata.com/help.cgi?search
*   http://www.stata.com/support/faqs/resources/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/faqs/resources/statalist-faq/
*   http://www.ats.ucla.edu/stat/stata/


© Copyright 1996–2018 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   Site index