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: RE: Fwd: foreach loop for generating missing variables


From   andreas chai <[email protected]>
To   [email protected]
Subject   Re: st: RE: Fwd: foreach loop for generating missing variables
Date   Sat, 24 Sep 2011 15:01:20 +1000

Thanks Jesper and Nick .. ! Both of your solutions work great ! your
efforts are much appreciated - that problem has been killing me all
week.

btw, Jesper, the background was that i was trying to merge two
datasets in which some variables existed in one dataset, but some only
existed in one dataset

so i needed to creat these empty variables in order to allow me to
merge and add variables together

thanks again.

cheers

andreas



On Fri, Sep 23, 2011 at 5:00 PM, Jesper Lindhardsen
<[email protected]> wrote:
> Hi Andreas
>
> This should work, although a crude method:
>
> forvalues val=100/894{
>        capture gen x`val'=.
> }
>
> I must admit that I think your reason(s) for doing this should be
> re-evaluated ;-)
>
> HTH,
>
> Jesper
>
>
> -----Original Message-----
> From: [email protected]
> [mailto:[email protected]] On Behalf Of andreas chai
> Sent: 23 September 2011 03:16
> To: statalist
> Subject: st: Fwd: foreach loop for generating missing variables
>
> Dear Stata experts :  PLease help!
>
> I have a series of variables "x100 ... x894" in which many of these
> variables are missing. e.g. x240 does not exist
>
> I would like to create these missing variables which contain zero for
> all
> observations.
>
> how do i create these missing variables ?
>
> i have tried writing a loop
>
> !foreach x of newlist  x100- x894{
> !gen `x=92 =3D0
> !}
>
> but keep getting an error as some these variables already exist.
>
>
> thank you in advance,
> Andreas
> *
> *   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/


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