Announcement

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

  • please help variable __000000 already defined

    when i try to collapse to get share of large firms, by country and year

    stata returns an error saying variable __000000 already define

    below is the command written in the do-file :

    collapse (mean) maxyear (sum) one large1 large2, by(country year)

    please assist me where possible



  • #2
    Have a look at the variable

    Code:
    tab __000000  
    
    su __000000
    If it looks interesting or useful, keep it under another name:

    Code:
    rename __000000 somethingelse
    Otherwise

    Code:
    drop __000000
    and try again.

    Comment


    • #3
      when i drop the variable and continue running my do-file it breaks and then says variable _00000 not found

      Comment


      • #4
        I can't answer that so easily.

        Code:
        __000000
        is the name of a temporary variable. It's possible that your do-file creates a temporary variable beforehand. The way to find out is to look at it for the key term tempvar (or just possibly tempname).

        We would need to see that code.

        How long is your do-file? If it is 3 or 30 lines, show it here. If it is 300 or 3000 or ..., it's less likely that even if you posted it, anyone would want to read it all, but showing us any use of temporary variables might help.

        Otherwise I am out of guesses.

        Comment


        • #5
          My do-file doesn't have tempvar or tempname.

          my do file is 177 lines.


          This is what my do-file looks like (not all of it though)

          so immediately when stata gets to the first collapse command it gives me those errors


          clear
          set more off
          set type double
          drop _all

          capture do "C:\Busi\code\setpath.do"


          cd "$root\data_cleaned"
          log using "3_dta.log", replace

          use "crosscountry_prepped.dta", clear


          ************************************************** *****************************
          ************************ 3a) LARGE FIRM SHARES ********************************
          ************************************************** *****************************

          //large firm shares
          preserve
          //collapse to get share of large firms, by country and year

          collapse (mean) maxyear (sum) one large1 large2, by(country year)
          gen large1share = large1/one*100
          gen large2share = large2/one*100
          label var large1share "Share of large firms, 100+ empl. (in %)"
          label var large2share "Share of large firms, 300+ empl. (in %)"
          //export share of large firms in maxyear, by country
          keep if year == maxyear
          keep country year large1share large2share
          export excel using $output\part3\tables, sheetreplace sheet("shares_large_maxyear") firstrow(varlabels)
          restore
          preserve
          //collapse to get average share of large firms, by country
          collapse (sum) one large1 large2, by(country)
          gen large1share=large1/one*100
          gen large2share=large2/one*100
          label var large1share "Share of large firms, 100+ empl. (in %)"
          label var large2share "Share of large firms, 300+ empl. (in %)"
          keep country large1share large2share
          export excel using "$output\part3\tables", sheetreplace sheet("shares_large_mean") firstrow(varlabels)
          restore

          Comment


          • #6
            Show us the results of

            Code:
            use crosscountry_prepped.dta
            describe

            Comment


            • #7
              i cant copy the whole thing it wont allow me to do it even when i try copying it as a picture

              Comment


              • #8
                If you type those commands you will see results (text printed in the Results window). That's all I am asking for. Here is something similar from my Stata. I highlighted a block of text and copied and pasted into the Statalist software using CODE delimiters. Do please read FAQ Advice #12.

                Code:
                . sysuse auto, clear
                (1978 Automobile Data)
                
                . describe
                
                Contains data from C:\Program Files\Stata15\ado\base/a/auto.dta
                  obs:            74                          1978 Automobile Data
                 vars:            12                          13 Apr 2016 17:45
                 size:         3,182                          (_dta has notes)
                ----------------------------------------------------------------------------------------
                              storage   display    value
                variable name   type    format     label      variable label
                ----------------------------------------------------------------------------------------
                make            str18   %-18s                 Make and Model
                price           int     %8.0gc                Price
                mpg             int     %8.0g                 Mileage (mpg)
                rep78           int     %8.0g                 Repair Record 1978
                headroom        float   %6.1f                 Headroom (in.)
                trunk           int     %8.0g                 Trunk space (cu. ft.)
                weight          int     %8.0gc                Weight (lbs.)
                length          int     %8.0g                 Length (in.)
                turn            int     %8.0g                 Turn Circle (ft.)
                displacement    int     %8.0g                 Displacement (cu. in.)
                gear_ratio      float   %6.2f                 Gear Ratio
                foreign         byte    %8.0g      origin     Car type
                ----------------------------------------------------------------------------------------
                Sorted by: foreign

                Comment


                • #9
                  Hi Nick

                  im so sorry for taking long to respond i finally figured out a way to send you my data because i have been struggling with that. i ended up changing the variable names like you suggested and it worked. however today i'm faced with another problem.

                  i keep on encountering a "unmatched quote" error when trying to use the twoway command in a loop. attached is a 3 pictures (the data set, the do file and the error msg)
                  Click image for larger version

Name:	graphs.PNG
Views:	1
Size:	23.4 KB
ID:	1456487
                  Click image for larger version

Name:	do file.PNG
Views:	1
Size:	21.7 KB
ID:	1456488
                  Click image for larger version

Name:	error message.PNG
Views:	1
Size:	20.7 KB
ID:	1456489

                  Comment


                  • #10
                    please help where possible. thanks

                    Comment


                    • #11
                      The reason you got the "unmatched quote" message is an unmatched quote. Code posted as images is not always easy to read or work with but the part of the code starting

                      Code:
                      label(2
                      looks wrong to me.

                      Comment


                      • #12
                        i'm so sorry for that.

                        is it a spacing issue or?

                        Comment


                        • #13
                          No; it looks like an unmatched quote. Sometimes Stata gets confused, but it's best to look for an unmatched quote given that message.

                          I see what looks like

                          Code:
                          label 2 "surviving firms, T-5
                          and I see no closing quote.

                          If your image has truncated your code, then please re-post your graph command as copied-and-pasted text.

                          Comment


                          • #14
                            Nick's comment in posts #11 and #13 is based on your third picture in post #9. But the second picture shows what the code was that was being run; your third picture chops off the rightmost edge of the Stata output, and Nick did not realize this.

                            I'm going to take a step back. In the first topic you posted on Statalist you told us

                            this is my first time using stata
                            and

                            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
                            Assistance of this sort is not a good match for Statalist. Your problems are not with Stata commands that we can help you with, your problems are with a group of do-files written by someone else, do-files that we have no access to nor understanding of.

                            You should be seeking help from the authors of the do-files, or from the persons who assigned you the task of running the do-files. If that help is not available, then this task is not an appropriate assignment for someone new to Stata.

                            I will note that the code you show us above includes the global macro $output, which perhaps has embedded with it an unmatched quote. But that's just a guess, because the code you show in post #9 starts 53 lines into the do-file you are running. We don't know how $output was created or what it contains.

                            I am sorry to be unable to help with this. When you are writing Stata do-files of your own, Statalist will be in a better position to help you, because you will have a better understanding of what you have written.

                            Comment


                            • #15
                              William is right. I suspect that you need to show us the local macro countries. Any name like "Czech Republic" in double quotes needs extra care. On the other hand, if you have inherited these do files did they work previously?

                              Comment

                              Working...
                              X