# Re: st: Help with a loop

 From "Ada Ma" To statalist@hsphsun2.harvard.edu Subject Re: st: Help with a loop Date Mon, 16 Jul 2007 15:15:10 +0100

Hi Guillermo,

gen string = string( Var1)+ string( Var2) + string( Var3) + string( Var4)
replace string = subinstr(string, ".","",.)
drop Var*
gen Var1 = substr(string,1,1)
gen Var2 = substr(string,2,1)
...

so on and so forth

This would work if all your numbers are single digits / all have
identical digits.  If they aren't consider generating string versions
of the variables and make them all the same lengths (put zeros in
front of small numbers), and then put them all together in one
variable, stripe out the spaces and missing's, and cut them apart
again.  Tedious but would work.

Hope this helps.

On 7/16/07, Guillermo Villa <guillermo@baphealth.com> wrote:
Dear statalisters,

I am working on a dataset that looks like this:

Var11 =09Var12=09Var13=09Var14=09Var15
1=092=093=09.=095
=092=094=09.=09.
3=09.=094=09.=096
=09.=09.=093=09.=09.

I would need to move all the values to the left, skipping the missing value=
s:

Var11 =09Var12=09Var13=09Var14=09Var15
1=092=093=095=09.
2=094=09.=09.=09.
3=094=096=09.=09.
3=09.=09.=09.=09.

I have tried the following:

foreach i of numlist 1/4 {
if Var1`i'=3D=3D. {
replace Var1`i'=3DVar1`i'+1
replace Var1`i'+1=3D=3D.
}
}

But I get this warning: + invalid name r(198), which refers to the
last replace command=85

of doing it?

Thanks.

Guillermo

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