Statalist


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

Re: st: Re: -encode- help..


From   "Martin Weiss" <[email protected]>
To   <[email protected]>
Subject   Re: st: Re: -encode- help..
Date   Wed, 19 Nov 2008 21:32:58 +0100

Nick`s contribution makes me think that it is possible to automate this in the fashion that you describe...

HTH
Martin
_______________________
----- Original Message ----- From: "moleps islon" <[email protected]>
To: <[email protected]>
Sent: Wednesday, November 19, 2008 9:28 PM
Subject: Re: st: Re: -encode- help..


So apparently no easy solution to this. The perfect solution would be
a command that accepted a varlist, automatically generated new
variables concatenating the old variablename with a userspecified
_name_ and labeled the values according to a predefined labelset...
That would also let the user set the startnumber for the codes...
Gotta learn programming:-)



On Wed, Nov 19, 2008 at 9:17 PM, Martin Weiss <[email protected]> wrote:
Some amount of beforehand investigation is thus inevitable. If Moleps could find one variable that had all possible values present, he could substitute
that in the line "encode sex, g(gender)" and it would work...

HTH
Martin
_______________________
----- Original Message ----- From: "Sergiy Radyakin"
<[email protected]>
To: <[email protected]>
Sent: Wednesday, November 19, 2008 9:11 PM
Subject: Re: st: Re: -encode- help..


Hi,

this will not work in case when one of the variables does not contain
all codes present in all other variables.

(table shows unique values only,sorted alphabetically, like Stata does it)

Var1 Var2 Var3
A       B       A
B      C       B
C

After encoding Var1 will be coded as 1=A, 2=B, 3=C; Var2: 1=B, 2=C;
Var3: 1=A,2=B, which is in all probability not what moleps islon
wanted.

In general one must find a union of all possible values, then encode.
Practically this is probably easier to solve by reshaping the data to
the long format, encoding the single string variable, and then
reshaping back. If there are a few values to label, and those are
known a priori, I would hardwire them into the program and label
manually.

Best regards,
 Sergiy Radyakin

On Wed, Nov 19, 2008 at 2:52 PM, Martin Weiss <[email protected]>
wrote:

Well, if they share the same values, then the -encode- will lead to a
redundancy because technically you would need only one -label- so that

**************
webuse hbp2, clear

forv i =1/5{
clonevar sex`i'=sex
}

encode sex, g(gender)

ds sex?

foreach var in `r(varlist)'{
encode `var', g(gender`var') l(gender)
}

desc
*****************

you can reuse it with the -label- option to -encode-...


HTH
Martin
_______________________
----- Original Message ----- From: "moleps islon" <[email protected]>
To: <[email protected]>
Sent: Wednesday, November 19, 2008 8:30 PM
Subject: st: -encode- help..


I've got 30 different text variables that all have the same possible
values. Is there an easy way to encode all 30 variables using the same
label or do I have to do it manually. Also is it possible, somehow, to
specify stata to start encoding with tha value 0 instead of 1 ?

Best wishes,
Moleps
*
*   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/



*
*   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–2024 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   What's new   |   Site index