Announcement

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

  • Adding label values

    Hello,
    I have an Excel file with survey of different approaches for an operation. I imported it into Stata 13. One of the variables is called 'approach'. The values of the 'approach' are: frontal, parietal, occipital, temporal.

    When I used the command codebook (.codebook approach) I noticed that the values of the variables do not have label values.

    I had tried: label define > ... and then label value .... However, I got an error message: 'may not label strings'

    I tried changing the value labels by going to variable manager. However, the 'label value' option was greyed out.

    After a 36 hours of working on this I have managed to add label values by encoding the variable 'approach' to 'approach 2'. Is there any other other better way of adding 'label values'?

    Many thanks in advance!

    Naren



  • #2
    Hello Ganesalingam,

    If you want to preserve strings as labels, I would just do this:

    Code:
    . encode approach, gen(approach2)
    . codebook approach2
    Best,

    Marcos
    Last edited by Marcos Almeida; 05 Oct 2015, 04:34.
    Best regards,

    Marcos

    Comment


    • #3
      approach is evidently a string variable with distinct values frontal, parietal, occipital, temporal

      So far, so good. There are some reasons for mapping that to a numeric variable, principally if you wanted to use that variable as a predictor in a model or use a graph command that won't accept a string variable.

      String variables can't have value labels in Stata.

      Code:
      encode approach, gen(approach2)
      would create a numeric variable with value labels assigned in alphanumeric order, namely 1 "frontal" 2 "occipital" 3 "parietal" 4 "temporal".

      If you want some other order, you need to define labels in advance, but help encode explains how to do that.

      At some point the best way to learn Stata essentials is just to work through the first half or so of [U] in the .pdf documentation.

      Comment


      • #4
        Many thanks!

        Comment

        Working...
        X