Announcement

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

  • Trouble plotting standard deviation - Sigma convergence

    Hi,

    I am new to Stata and have been trying to plot the standard deviation of my whole sample and that of one subgroup.


    This is my code:

    bysort year: egen y_sd=sd(y)
    by year: egen y_sd_EU15=sd(y) if EU15==1
    label var y_sd "Standard deviation of real GDP per capita"
    label var y_sd_EU6 "Standard deviation of real GDP per capita - EU15"
    tsline y_sd y_sd_EU15 if year>=1995, xlabel (1995(10)2018)


    After the bysort command "type mismatch" pops up.


    Could someone please help?

    Kat

  • #2
    Originally posted by Kat Furst View Post
    After the bysort command "type mismatch" pops up.
    If the error message happens during executing of the first line of code, then y is a string variable.

    If the error message occurs while executing the next line of code, then EU15 is a string variable.

    Comment


    • #3
      I guess also that you don't mean

      Code:
      label var y_sd_EU6 ...
      but rather

      Code:
      label var y_sd_EU15 ...

      Comment


      • #4
        Thank you both!

        Yes I meant EU15 and not EU6. It must have been that y is a string variable, I now sorted the problem using the following code:

        encode y, gen(y_n)

        y is a numerical variable in my data set (GDP per capita), so I don't really understand why it was interpreted as a string variable?

        Comment


        • #5
          Originally posted by Kat Furst View Post
          encode y, gen(y_n)

          y is . . . GDP per capita
          Don't do that.

          Use encode only with nominal categorical string data.

          If you have quantitative values that accidentally got rendered as string variables, do the following instead to convert them back to numerical variables.
          Code:
          generate double y_n = real(y)
          You can use generate float . . . if the values will fit into that data type, and if they're integers, you can use one of the integer data types instead of double or float.

          Comment


          • #6
            Originally posted by Joseph Coveney View Post
            Don't do that.

            Use encode only with nominal categorical string data.

            If you have quantitative values that accidentally got rendered as string variables, do the following instead to convert them back to numerical variables.
            Code:
            generate double y_n = real(y)
            You can use generate float . . . if the values will fit into that data type, and if they're integers, you can use one of the integer data types instead of double or float.
            I have now tried:

            Code:
            generate double y_n = real(y)
            and

            Code:
            generate float y_n= real(y)
            For both, no error is reported but on the Standard deviation graph nothing shows up, it's completely blank.


            I also tried:

            Code:
             destring y, generate(y_n)
            whereafter Stata reports: "y: contains nonnumeric characters; no generate"

            and
            Code:
            destring y, generate(y_n) force
            whereafter Stata reports: "y: contains nonnumeric characters; y_n generated as byte"
            But here again, nothing shows up on the graph.

            Comment


            • #7
              you probably do not want the force option; instead, start with
              Code:
              ta y if real(y)==.
              then, assuming there are only a small number of problems, you can use the "ignore" option of -destring-

              Comment


              • #8
                Thanks a lot for your help! It worked.

                Comment

                Working...
                X