[Date Prev][Date Next][Thread Prev][Thread Next][Date index][Thread index]

Re: st: Help with a loop

From   "Ada Ma" <>
Subject   Re: st: Help with a loop
Date   Mon, 16 Jul 2007 15:15:10 +0100

Hi Guillermo,

I don't think you need a loop.  How about this:

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 <> wrote:
Dear statalisters,

I am working on a dataset that looks like this:

Var11 =09Var12=09Var13=09Var14=09Var15

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

Var11 =09Var12=09Var13=09Var14=09Var15

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

Could you please help me? Do you think there is a more convenient way
of doing it?



*   For searches and help try:

*   For searches and help try:

© Copyright 1996–2017 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   What's new   |   Site index