Notice: On March 31, it was **announced** that Statalist is moving from an email list to a **forum**. The old list will shut down on April 23, and its replacement, **statalist.org** is already up and running.

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

From |
daniel klein <klein.daniel.81@googlemail.com> |

To |
statalist@hsphsun2.harvard.edu |

Subject |
Re st: destring_loop |

Date |
Sat, 18 Aug 2012 10:33:43 +0200 |

As Phil shows, no loops are needed here. Another solution is unab vars : * gettoken first vars : vars destring `vars' ,replace If I was writing a do-file, I would probably use the -ds- approach. There is one line less typing involved, and it is presumably easier to understand (for a lot of people). Writing a program, I would rely on my code, because -ds- is (too) powerful, meaning that it is about 300 lines of interpreted code, where only two lines are needed for this specific problem. Even though it is not needed here, Stata stores the number of variables in the current dataset in c(k). A loop would look like forv j = 2/`=c(k)' { [...] } Best Daniel -- I have imported an Excel worksheet to Stata but all numerical variables was converted to string. I want to use destring to convert these string variables to numeric for all variables except the first variable. Imagine there are 10 variables (Var 1 – Var 10) and the first variable should remain in string format. I have write the following command and it works correctly. destring Var2– Var10, replace This conversion (string to numeric) should be done for a lot of data set with varying length and in each data set the first variable should remain in string format. I want to write a loop for these task and want to use this command in that loop but I don’t khow how is possible to call second variables till the end as we usually done for numeric values ( for example 2/max) Would you please help me to find a good solution? * * 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/

**Follow-Ups**:**Re: Re st: destring_loop***From:*Phil Clayton <philclayton@internode.on.net>

- Prev by Date:
**Re: st: destring_loop** - Next by Date:
**Re: st: destring_loop** - Previous by thread:
**st: destring_loop** - Next by thread:
**Re: Re st: destring_loop** - Index(es):