Stata The Stata listserver
[Date Prev][Date Next][Thread Prev][Thread Next][Date index][Thread index]

st: RE: RE: RE: Label problem


From   "Nick Cox" <[email protected]>
To   <[email protected]>
Subject   st: RE: RE: RE: Label problem
Date   Wed, 5 Oct 2005 23:20:47 +0100

I have a blind spot with -recode-. Because I rarely use it, the 
syntax is a mystery each time, so I rarely use it. It's a brilliant
command, but it's not for me. So, what the issue is with -recode- others 
may be able to explain. 

This is how I would tackle your problem: 

label def agreesc 1 "strongly disagree" 2 "disagree" 
	3 "agree somewhat" 4 "strongly agree"

qui forval i = 143/152 {  
	gen q`i'r = 5 - q`i' if inrange(q`i',1,4) 
	label val q`i'r agreesc 
} 

The mapping from 98 and 99 to . is a deliberate
side-effect of the -generate-. It is worth 
remembering the reversal rule -- here 5 - original -- 
as spelling out code by code is more tedious and 
more error-prone. A hand-waving argument with 
five digits helps convince (i.e. it's a reflection). 

Nick 
[email protected] 

Alexandra de Montrichard
 
> Nick - Sorry. Let me try to give more information:
> 
> Here is what I'm trying to do: 
> I have variables (q143-q152) with values 1 to 4 with the labels 
>            1 strongly agree
>            2 agree somewhat
>            3 disagree
>            4 strongly disagree
>           98 don't know
>           99 refused
> I want to create new variables (q143r-152r)in which values 98 
> and 99 are
> recoded as . and values 1 to 4 are in reverse order and the new labels
> are:
> 1 "strongly disagree" 2 "disagree" 3"agree somewhat" 4"strongly agree"
> 
> Here is what I've done:
> 1) I defined labels:
> label define agreesc 1 "strongly disagree" 2 "disagree" 3"agree
> somewhat" 4"strongly agree"
> 2) I then recode the old variable into new variables and 
> added the label
> agreesc to the new variables (the text below is all on one line in my
> code):
> recode q143 q144 q145 q146 q147 q149 q150 q151 q152  (1=4) (2=3) (3=2)
> (4=1), gen(q143r q144r q145r q146r q147r q149r q150r q151r 
> q152r) label
> (agreesc)
> 3) I compared my old & new variable and found that the new 
> variables did
> not have value labels:
> 
> . tab q143 q143r
> 
>     q143. in this |
>  organization, it | RECODE of q143 (q143. in this organization,
> is more important |      it is more important to get inpu)
>       to get inpu |         1          2          3          4 |
> Total
> ------------------+-------------------------------------------
> -+--------
> --
>    strongly agree |         0          0          0        125 |
> 125 
>    agree somewhat |         0          0        124          0 |
> 124 
>          disagree |         0         86          0          0 |
> 86 
> strongly disagree |        29          0          0          0 |
> 29 
> ------------------+-------------------------------------------
> -+--------
> --
>             Total |        29         86        124        125 |
> 364 
> 
> 4) If I manually add the labels & run the same table I get 
> the result I
> was looking for. However, I don't understand why step 2 above 
> did not do
> add the value labels for variables q143r to q152r.
> 
> . label values q143r agreesc
> 
> . tab q143 q143r
> 
>     q143. in this |
>  organization, it | RECODE of q143 (q143. in this organization,
> is more important |      it is more important to get inpu)
>       to get inpu | strongly    disagree  agree som  strongly  |
> Total
> ------------------+-------------------------------------------
> -+--------
> --
>    strongly agree |         0          0          0        125 |
> 125 
>    agree somewhat |         0          0        124          0 |
> 124 
>          disagree |         0         86          0          0 |
> 86 
> strongly disagree |        29          0          0          0 |
> 29 
> ------------------+-------------------------------------------
> -+--------
> --
>             Total |        29         86        124        125 |
> 364 
> 
> 
> Any advise you can provide would be greatly appreciated.

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



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