Thank you Michael. What you showed is what I need, especially the program.
On 10/13/05, Michael Blasnik <[email protected]> wrote:
> -destring- is for when you have a string that is all numeric characters and
> you want to convert to the numeric. You should use -encode- to convert text
> strings to numeric. If you have many of these Y/N type fields, it may be a
> good idea to define one value label and use that for all of them:
>
> label define yesno 0"N" 1"Y"
> encode v1, gen(vv1) label(yesno)
>
> You may want to write a little ado file to automate this and copy over
> variable labels, move the new variable to the location of the old variable,
> drop the old variable and rename the new one.
>
> program define yesno
> syntax varlist
> foreach v of local varlist {
> tempvar newv
> local vl: variable label `v'
> encode `v', gen(`newv') label(yesno)
> label var `newv' `"`vl'"'
> move `newv' `v'
> drop `v'
> rename `newv' `v'
> }
> end
>
> label define yesno 0"N" 1"Y"
> yesno v1 v2 v3
>
>
> Michael Blasnik
> [email protected]
>
> ----- Original Message -----
> From: "Jia Xiangping" <[email protected]>
> To: "statalist" <[email protected]>
> Sent: Thursday, October 13, 2005 9:32 AM
> Subject: Re: st: How to cope with string when transfrom from Epidata to
> Stata
>
>
> > Additionally, when I run -
> > . destring v1, generate(vv1) float
> >
> > I was informed that
> > v1 contains non-numeric characters; no generate
> >
> > What's wrong?
> >
> > On 10/13/05, Jia Xiangping <[email protected]> wrote:
> >> Dear all,
> >>
> >> When data were input from questionnaires, epidata (version3.1) was
> >> used. One question, as "Did you applied credit last year", was set as
> >> "Boolean (yes/no)" in Epidata. But when data was exported to Stata
> >> 8.2, the result is very frustrating:
> >><snip>
> >> What I need is just a binary variable. Must I have to transform it to
> >> numerical variable firstly and then label variables and values again
> >> manually? Are there any other ways I can apply?
> >>
> >> If I could foresee this problem, I would have defined variable v1 as
> >> just numerical type in Epidata instead of "Boolean".
> >>
> >>
> >> --
> >> Xiangping JIA
>
> *
> * 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/
>
--
Xiangping JIA
*
* 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/