Announcement

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

  • Problem with a numeric variable

    Hello Stata community;
    I dispose of the data:
    Code:
    * Example generated by -dataex-. To install: ssc install dataex
    clear
    input int year str6 sunspotsnumber long Sunspots
    1981 "140.4"   7
    1982 "115.9"   4
    1983 "66.6"   22
    1984 "45.9"   18
    1985 "17.9"   12
    1986 "13.4 "   6
    1987 "29.4"   14
    1988 "100.2"   1
    1989 "157.6 " 10
    1990 "142.2"   8
    1991 "145.8"   9
    1992 "94.5"   25
    1993 "54.7"   19
    1994 "29.9"   16
    1995 "17.5"   11
    1996 "8.6 "   23
    1997 "21.6"   13
    1998 "64.2"   21
    1999 "93.4"   24
    2000 "119.6 "  5
    2001 "110.9"   3
    2002 "104.1"   2
    2003 "63.6"   20
    2004 "40.4"   17
    2005 "29.8"   15
    end
    label values Sunspots Sunspots
    label def Sunspots 1 "100.2", modify
    label def Sunspots 2 "104.1", modify
    label def Sunspots 3 "110.9", modify
    label def Sunspots 4 "115.9", modify
    label def Sunspots 5 "119.6 ", modify
    label def Sunspots 6 "13.4 ", modify
    label def Sunspots 7 "140.4", modify
    label def Sunspots 8 "142.2", modify
    label def Sunspots 9 "145.8", modify
    label def Sunspots 10 "157.6 ", modify
    label def Sunspots 11 "17.5", modify
    label def Sunspots 12 "17.9", modify
    label def Sunspots 13 "21.6", modify
    label def Sunspots 14 "29.4", modify
    label def Sunspots 15 "29.8", modify
    label def Sunspots 16 "29.9", modify
    label def Sunspots 17 "40.4", modify
    label def Sunspots 18 "45.9", modify
    label def Sunspots 19 "54.7", modify
    label def Sunspots 20 "63.6", modify
    label def Sunspots 21 "64.2", modify
    label def Sunspots 22 "66.6", modify
    label def Sunspots 23 "8.6 ", modify
    label def Sunspots 24 "93.4", modify
    label def Sunspots 25 "94.5", modify
    The problem is with variables "sunspotsnumber" and "Sunspots". As you can see, the first one is taken by Stata an a string variable, whci means I can't apply any numeric command on it (like the mean and the twoway line commands, which is my goal already), I've tried to destring it, it didn't work, I tried the encore and generate commands, and what Stata generated was the second variable "Sunspots". When I typed edit, all seemed kinda well, but when I demanded the mean of the variable "Sunspots" (the generated one which seems ok and in a numeric form), Stata gives the result that the mean of this variable "Sunspots" is 13, which clearly isn't since there are some values of this variable that go to 100 and even more. I don't know if it's the deciam part of this variable that's causing problems,even if I try to draw a twoway line graph between the variable "year" as an X-axis and the variable "Sunspots" as a Y-axis, the Y-axis shows the scale 5-10-15-20-25-...which is not the correct scale already.

    Can I have some help please? I really appreciate it.

  • #2
    It appears that you encoded the variable "sunspotsnumber" instead of destringing it.

    Code:
    decode Sunspots, g(sunspots)
    destring sunspots, replace
    drop Sunspots

    Comment


    • #3
      you don't show the code you tried but the following works for me:
      Code:
      destring sun, replace

      Comment


      • #4
        I guess it was just a destringing problem for some values, yet still, it's a problem :p Problem solves thanks to your suggestions. Thanks very much.

        Comment

        Working...
        X