Announcement

Collapse
No announcement yet.
X
  • Filter
  • Time
  • Show
Clear All
new posts

  • Showing the label and the numerical value of a byte variable

    Hello,
    this question may be trivial, but I want to know if there is a way to show both the label and the numeric value of a byte variable.

    Thank you for your time.

  • #2
    Yes, enter the following which adds the code to the value label:
    Code:
    numlabel, add

    Comment


    • #3
      Also consider downloading the user-written -fre- command. -findit fre-
      -------------------------------------------
      Richard Williams, Notre Dame Dept of Sociology
      Stata Version: 17.0 MP (2 processor)

      EMAIL: [email protected]
      WWW: https://www3.nd.edu/~rwilliam

      Comment


      • #4
        The -fre- command is fine, but with -numlabel- you get what you want also with twoway tables, regression output, etc.

        Comment


        • #5
          Thank you both.

          I used the -fre- command and it works fine. The way I want it. It shows both labels and its numerical value.

          Now, about the command -numlabel-, I have some problems implementing it. Let us say that I have a variable called `var1' which is in byte format. I tried something like:

          numlabel var1, add

          , but I got the error: value label var1 not found.

          Comment


          • #6
            You have to specify the value label name you want to add the numbers to, not the name of the variable. A single value label definition may be applied to multiple variables.

            Comment


            • #7
              OK,

              maybe I did not specify the question well. Let me elaborate a bit. Assume var1 to be a byte variable. This has values such as: a, b, c, d, with a = 1, b = 5, c = 15, d = 0. If you run a tab var1, you will get a, b, c, and d w/o the numerical values.

              As I said before, I wanted to know a command that shows both a, b, c, and d with their actual numerical values in one table. As such the -fre- command does the job well. I guess that numlabel is inappropriate in this case.

              Comment


              • #8
                Pantelis, I think you misunderstand. numlabel is actually going to change the value label so the numeric value is added on to it as a prefix. fre may be fine for what you want to do but, as Svend notes, if you ever want to do something like twoway tables then numlabel may serve your purposes better.
                -------------------------------------------
                Richard Williams, Notre Dame Dept of Sociology
                Stata Version: 17.0 MP (2 processor)

                EMAIL: [email protected]
                WWW: https://www3.nd.edu/~rwilliam

                Comment


                • #9
                  There is also an older but very useful program from the old Stata Technical Bulletin, tabl. I can't find a way to attach it here, but here is the code: Just use it as a one-way tab.

                  . type c:\ado\stbplus\t\tabl.ado
                  *! version 1.1.0 05oct1999 Jeroen Weesie/ICS (STB-53: dm75)
                  program define tabl
                  version 6.0

                  syntax varlist [if ] [in] [, Width(int 40)]

                  tokenize `varlist'
                  while "`1'" != "" {
                  Tabl `1' `if' `in', width(`width')
                  mac shift
                  }
                  end


                  /* Tabl varname [if] [in], width(#)
                  displays a one-var tabulate with varlabel and value labels,
                  wrapping if their length exceeds width
                  */
                  program define Tabl
                  syntax varname [if] [in], Width(int)

                  marksample touse, novarlist

                  local lab : value label `varlist'
                  if "`lab'" == "" {
                  * no value labels
                  tab `varlist' if `touse', miss
                  exit
                  }

                  tempname freq code

                  qui tab `varlist' if `touse', matcell(`freq') matrow(`code')
                  if r(N) == 0 {
                  exit
                  }
                  local N = r(N)

                  local vlab : var label `varlist'
                  if `"`vlab'"' == "" {
                  local vlab `varlist'
                  }
                  else local vlab `varlist' (`vlab')

                  * determine max length of varlabel and value labels
                  local len = length(`"`vlab'"')
                  local i 1
                  while `i' <= rowsof(`freq') {
                  local ci = `code'[`i',1]
                  local li : label (`varlist') `ci'
                  local len = max(`len', length(`"`li'"'))
                  local i = `i'+1
                  }
                  if `len' > `width' {
                  local len = `width'
                  }
                  local col1 = `len' + 3

                  di
                  local vlab1 : piece 1 `len' of `"`vlab'"'
                  local vlab2 : piece 2 `len' of `"`vlab'"'
                  local i 2
                  while `"`vlab2'"' ~= "" {
                  di in gr `"`vlab1'"'
                  local vlab1 `vlab2'
                  local i = `i'+1
                  local vlab2 : piece `i' `len' of `"`vlab'"'
                  }

                  di in gr "`vlab1'" _col(`col1') " code | freq "
                  di in gr _dup(`col1') "-" "--------+--------"

                  local i 1
                  while `i' <= rowsof(`freq') {
                  local ci = `code'[`i',1]
                  local li : label (`varlist') `ci'
                  local pli : piece 1 `len' of `"`li'"'

                  di in gr %`len's `"`pli'"' _col(`col1') %6.0f `ci' /*
                  */ " |" in ye %7.0f `freq'[`i',1]

                  * display the rest of the value label
                  local j 2
                  local pli : piece `j' `len' of `"`li'"'
                  while `"`pli'"' != "" {
                  di in gr %`len's `" `pli'"' _col(`col1') " |"
                  local j = `j'+1
                  local pli : piece `j' `len' of `"`li'"'
                  }

                  local i = `i'+1
                  }

                  qui count if (`varlist'==.) & (`touse'==1)
                  if r(N) > 0 {
                  di in gr _dup(`col1') "-" "--------+--------"
                  di in gr %`len's "<missing value>" _col(`col1') " . |" /*
                  */ in ye %7.0f r(N)
                  }

                  di in gr _dup(`col1') "-" "--------+--------"
                  di in gr _col(`col1') " Total |" in ye %7.0f = `N'+r(N)
                  end

                  exit
                  ---------+--------
                  variable label code | freq
                  ------------------------------------+---------
                  123456789012345678901234 1234 | 123456
                  (continued) |
                  123456789012345678901234 1234 | 123456
                  ------------------------------------+---------
                  <missing value> . | 123456
                  ------------------------------------+---------
                  Total | 123456

                  .

                  Comment


                  • #10
                    Pantelis, numlabel is really what you are asking for. See:
                    Code:
                    help numlabel
                    numlabel modifies existing value labels; it does not create them. You can use numlabel with and without specifying a label name; in the latter case it is applied to all value labels:
                    Code:
                    numlabel labelname , add
                    or
                    numlabel , add

                    Comment


                    • #11
                      Hello,

                      I may have a very specific problem in connection with the numlabel-command: I use Stata 14.2 for Unix on a Linux-server to run my analyses.

                      If I enter -numlabel, add- into the prompt I receive the error message "value label FILTER_ not found".
                      The same happens if I go through the drop-down menu (-. numlabel, add mask("#. ") force)

                      Has anyone else experienced this error message? Could it be in conjunction with using a server-version?
                      Any advice?

                      BTW: the -fre-ado works well, but I would like to have numlabels for a broader range of analyses.

                      Comment


                      • #12
                        Hi all

                        I have a question about the numlabel command and when to apply it. When I set ‘numlabel, add’ it does exactly as it should for the session, but when I generate a new variable the values for this variable do not appear against the labels when running a tabulate, for example. To get this information again I need to rerun ‘numlabel, add’.

                        Am I correct in my assumption that the numlabel command applies to all values in the current variable list at the time of execution, but when generating a new variable it needs to be reapplied?

                        Thanks in advance for your time
                        Jen

                        Comment

                        Working...
                        X