Announcement

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

  • Type mismatch error please help

    Hi everyone

    May anyone kindly assist me with fixing the type mismatch error.

    here is the command i wrote : replace manufacturing = 0 if manufacturing == . & sector!= ""

    please help . this is my first time using stata




  • #2
    Your code is legal if manufacturing is numeric and sector is string, but not if either is false.

    So look at the results of

    Code:
    describe manufacturing sector
    to see which variables are string and numeric.

    Comment


    • #3
      manufacturing is a string variable and sector is a numeric variable ....do i need to change it around

      Comment


      • #4
        Yes as far as your command is concerned.. But if you think that a value of manufacturing should be 0, the implication is that it shouldn't be a string variable at all. Again, can you show results such as

        Code:
        tab manufacturing if missing(real(manufacturing))
        Please do study https://www.statalist.org/forums/help especially #12.

        Comment


        • #5
          describe manufacturing

          storage display value
          variable name type format label variable label
          ---------------------------------------------------------------------------------------------------------
          manufacturing double %10.0g

          . describe sector

          storage display value
          variable name type format label variable label
          ---------------------------------------------------------------------------------------------------------
          sector int %48.0g sector Sector (2 digit ISIC rev. 4)

          . tab manufacturing if missing(real(manufacturing))
          type mismatch
          r(109);

          Comment


          • #6
            You told us in #3 that manufacturing was string. But you're now showing us a result that shows that it is numeric (specifically double). Also sector is numeric. That being so, the code in #1 should be more like

            Code:
            replace manufacturing = 0 if manufacturing == . & sector != .
            Are you moving back and forth between different versions of the same data?

            Advice in #4 remains. Giving us a data example is the best way to get good help quickly.

            Comment


            • #7
              Your describe results in post #5 tell us that both manufacturing and sector are numeric variables, but your sector variable has a value label which displays the numeric values as strings. I've reposted the describe sector results using CODE delimiters (as requested in the FAQ) to make this more apparent.
              Code:
                            storage   display    value
              variable name   type    format     label      variable label
              --------------------------------------------------------------------------------
              sector           int    %48.0g     sector     Sector (2 digit ISIC rev. 4)
              The command
              Code:
              label list sector
              will tell you how the value label displays each numeric value in output.

              But because sector is numeric, regardless of its display, your original command in post #1 should have been
              Code:
              replace manufacturing = 0 if manufacturing == . & sector!=.

              Comment


              • #8
                Thank you so much that actually worked.

                the way I'm so confused, i was told to just run do-files. so basically i am doing something i don't understand and trying to figure out why some of the do-files break and making sure they run.

                Comment


                • #9
                  Welcome to Statalist, and to Stata.

                  If you will be continuing to use Stata, perhaps the following advice that I have given before to other Statalist members will be helpful to you as well.

                  I'm sympathetic to you as a new user of Stata - it's a lot to absorb. And even worse if perhaps you are under pressure to produce some output quickly, or as in your case, just told to "run the do-files" without any guidance.

                  When I began using Stata in a serious way, I started, as have others here, by reading my way through the Getting Started with Stata manual relevant to my setup. Chapter 18 then gives suggested further reading, much of which is in the Stata User's Guide, and I worked my way through much of that reading as well. There are a lot of examples to copy and paste into Stata's do-file editor to run yourself, and better yet, to experiment with changing the options to see how the results change.

                  All of these manuals are included as PDFs in the Stata installation (since version 11) and are accessible from within Stata - for example, through the PDF Documentation section of Stata's Help menu. The objective in doing the reading was not so much to master Stata as to be sure I'd become familiar with a wide variety of important basic techniques, so that when the time came that I needed them, I might recall their existence, if not the full syntax, and know how to find out more about them in the help files and PDF manuals.

                  Stata supplies exceptionally good documentation that amply repays the time spent studying it - there's just a lot of it. If you can make some time to work your way through this program of reading and trying out examples, you will become familiar with the things you need to know to get started in a hurry and to work effectively.

                  Comment


                  • #10
                    Hi William

                    Thank you so so much for your response. i will definitely check out the Getting started with stata manual and try to familiarize myself with the basics i need to can be able to understand what i'm doing. i did not even know stata had that option.

                    Thank you so much i really appreciate it.

                    Comment

                    Working...
                    X