Announcement

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

  • #16
    Hi All,

    I am trying to group countries in the same way as mentioned above. Everything goes well but when I type this command "label val groups gnames" , this error shows up "variable groups not found
    r(111);"

    Can anyone tell me what is going wrong in this case?

    Best Regards,

    Comment


    • #17
      Abdullah:
      are you sure you did not type:
      Code:
      label var groups gnames
      Kind regards,
      Carlo
      (Stata 19.0)

      Comment


      • #18
        I am pretty sure that I have typed : "label val groups gnames" .. what could go wrong?

        Comment


        • #19
          What could go wrong is that you do not have a variable groups -- which is precisely the error message. You need to tell us the code that preceded this.

          Comment


          • #20
            Thanks for your replies. Here is the code which I am using:


            gen groups = 1 * inlist(economy, "Australia", "Brunei Darussalam", "Cambodia", "China", "Fiji", "Hong Kong SAR, China", "Indonesia", "Japan", "Malaysia", "Myanmar", "New Zealand") + ///,
            1 * inlist(economy, "Philippines", "Singapore", "Solomon Islands", "Taiwan", "Thailand", "Papua New Guinea", "Vanuatu", "Vietnam") + ///
            2 * inlist(economy, "Afghanistan", "Bangladesh", "Bhutan", "India", "Papua New Guinea", "Maldives", "Nepal", "Pakistan", "Sri Lanka") ///

            label def gnames ///
            1 "EastAsia" ///
            2 "SouthAsia" ///

            label val groups gnames
            label var groups "Country income groups"

            Comment


            • #21
              Certainly looks odd. I would try without so many quite so many ///

              Code:
              gen groups = 1 * inlist(economy, "Australia", "Brunei Darussalam", "Cambodia", "China", "Fiji", "Hong Kong SAR, China", "Indonesia", "Japan", "Malaysia", "Myanmar", "New Zealand") + ///,
              1 * inlist(economy, "Philippines", "Singapore", "Solomon Islands", "Taiwan", "Thailand", "Papua New Guinea", "Vanuatu", "Vietnam") + ///
              2 * inlist(economy, "Afghanistan", "Bangladesh", "Bhutan", "India", "Papua New Guinea", "Maldives", "Nepal", "Pakistan", "Sri Lanka") 
              
              label def gnames ///
              1 "EastAsia" ///
              2 "SouthAsia" 
              
              label val groups gnames
              l

              Comment


              • #22
                Just to mention here that it worked for the first time and then I dropped that variable because I wanted to add more countries. After that, it didn't generate this variable. Is there anything else that could go wrong. Your help shall be highly appreciated.

                Comment


                • #23
                  I can't follow #22 easily. You need to show exact code, not describe it indirectly. But if you dropped a variable, it won't spring back into existence.

                  Comment


                  • #24
                    Thanks a lot Nick and all other people who replied. It is working now. I think there was some issue with the code which I sorted already. However, now when I write

                    label def gnames ///
                    > 1 "EastAsia" ///
                    > 2 "SouthAsia"
                    label gnames already defined
                    r(110);

                    This error pops up. Sorry for wasting a lot of your time but I appreciate if you can answer this query.

                    Best Regards,
                    A

                    Comment


                    • #25
                      I have used replace command and it worked. Many thanks to all of you!

                      Comment


                      • #26
                        Hello, I am trying to replicate this code but I am getting variable group not found. Can someone please tell me what I am doing wrong?Thankyou
                        gen groups= 1 * inlist(countrycode, "SYC", "NAM", "BWA", GNQ", "GAB", "LBY", "MUS", "ZAF")+///
                        2 * inlist(countrycode, "AGO", "DZA", "BEN", "CIV", "CMR", "COG", "COM", "CPV", "DJI")+///
                        2 * inlist(countrycode, "EGY", "GHA", "KEN", "LSO", "MAR", "MRT", "NGA", "SEN", "STP", "SWZ")+///
                        2 * inlist(countrycode, "TUN", "TZA", "ZWE") +///
                        3 * inlist(countrycode, "BDI", "BFA", "CAF", "COD", "ERI" , "ETH", "GIN" , "GMB" , "LBR", "MDG")+///
                        3 * inlist(countrycode, "MLI" , "MOZ", "MWI" , "NER", "RWA", "SDN", "SLE", "SOM" , "SSD" , "TCD")
                        3 * inlist(countrycode, "TGO", "UGA", "ZMB")+//
                        label def gnames ///
                        1 "Upper Income" ///
                        2 " lower middle Income" ///
                        3 "Low Income"
                        label val groups gnames


                        Comment


                        • #27
                          Code:
                          gen groups= 1 * inlist(countrycode, "SYC", "NAM", "BWA", GNQ", "GAB", "LBY", "MUS", "ZAF")+///
                          2 * inlist(countrycode, "AGO", "DZA", "BEN", "CIV", "CMR", "COG", "COM", "CPV", "DJI")+///
                          2 * inlist(countrycode, "EGY", "GHA", "KEN", "LSO", "MAR", "MRT", "NGA", "SEN", "STP", "SWZ")+///
                          2 * inlist(countrycode, "TUN", "TZA", "ZWE") +///
                          3 * inlist(countrycode, "BDI", "BFA", "CAF", "COD", "ERI" , "ETH", "GIN" , "GMB" , "LBR", "MDG")+///
                          3 * inlist(countrycode, "MLI" , "MOZ", "MWI" , "NER", "RWA", "SDN", "SLE", "SOM" , "SSD" , "TCD")
                          3 * inlist(countrycode, "TGO", "UGA", "ZMB")+//
                          should be

                          Code:
                          gen groups= 1 * inlist(countrycode, "SYC", "NAM", "BWA", GNQ", "GAB", "LBY", "MUS", "ZAF")+///
                          2 * inlist(countrycode, "AGO", "DZA", "BEN", "CIV", "CMR", "COG", "COM", "CPV", "DJI")+///
                          2 * inlist(countrycode, "EGY", "GHA", "KEN", "LSO", "MAR", "MRT", "NGA", "SEN", "STP", "SWZ")+///
                          2 * inlist(countrycode, "TUN", "TZA", "ZWE") +///
                          3 * inlist(countrycode, "BDI", "BFA", "CAF", "COD", "ERI" , "ETH", "GIN" , "GMB" , "LBR", "MDG")+///
                          3 * inlist(countrycode, "MLI" , "MOZ", "MWI" , "NER", "RWA", "SDN", "SLE", "SOM" , "SSD" , "TCD") + ///
                          3 * inlist(countrycode, "TGO", "UGA", "ZMB") 
                          There may be other errors, but those errors would break the code. That said, why those errors would yield that error message I can't say.

                          Comment


                          • #28
                            Originally posted by Nick Cox View Post
                            Code:
                            gen groups= 1 * inlist(countrycode, "SYC", "NAM", "BWA", GNQ", "GAB", "LBY", "MUS", "ZAF")+///
                            2 * inlist(countrycode, "AGO", "DZA", "BEN", "CIV", "CMR", "COG", "COM", "CPV", "DJI")+///
                            2 * inlist(countrycode, "EGY", "GHA", "KEN", "LSO", "MAR", "MRT", "NGA", "SEN", "STP", "SWZ")+///
                            2 * inlist(countrycode, "TUN", "TZA", "ZWE") +///
                            3 * inlist(countrycode, "BDI", "BFA", "CAF", "COD", "ERI" , "ETH", "GIN" , "GMB" , "LBR", "MDG")+///
                            3 * inlist(countrycode, "MLI" , "MOZ", "MWI" , "NER", "RWA", "SDN", "SLE", "SOM" , "SSD" , "TCD")
                            3 * inlist(countrycode, "TGO", "UGA", "ZMB")+//
                            should be

                            Code:
                            gen groups= 1 * inlist(countrycode, "SYC", "NAM", "BWA", GNQ", "GAB", "LBY", "MUS", "ZAF")+///
                            2 * inlist(countrycode, "AGO", "DZA", "BEN", "CIV", "CMR", "COG", "COM", "CPV", "DJI")+///
                            2 * inlist(countrycode, "EGY", "GHA", "KEN", "LSO", "MAR", "MRT", "NGA", "SEN", "STP", "SWZ")+///
                            2 * inlist(countrycode, "TUN", "TZA", "ZWE") +///
                            3 * inlist(countrycode, "BDI", "BFA", "CAF", "COD", "ERI" , "ETH", "GIN" , "GMB" , "LBR", "MDG")+///
                            3 * inlist(countrycode, "MLI" , "MOZ", "MWI" , "NER", "RWA", "SDN", "SLE", "SOM" , "SSD" , "TCD") + ///
                            3 * inlist(countrycode, "TGO", "UGA", "ZMB") 
                            There may be other errors, but those errors would break the code. That said, why those errors would yield that error message I can't say.
                            Thanks very much@Nick Cox
                            I have tried the code but its still not woring. This is the error message.
                            . gen groups= 1 * inlist(countrycode, "SYC", "NAM", "BWA", GNQ", "GAB", "LBY", "MUS", "ZAF")+///
                            too few quotes
                            r(132);

                            .
                            . 2 * inlist(countrycode, "AGO", "DZA", "BEN", "CIV", "CMR", "COG", "COM", "CPV", "DJI")+///
                            2 is not a valid command name
                            r(199);

                            .
                            . 2 * inlist(countrycode, "EGY", "GHA", "KEN", "LSO", "MAR", "MRT", "NGA", "SEN", "STP", "SWZ")+//
                            > /
                            2 is not a valid command name
                            r(199);

                            .
                            . 2 * inlist(countrycode, "TUN", "TZA", "ZWE") +///
                            2 is not a valid command name
                            r(199);

                            .
                            . 3 * inlist(countrycode, "BDI", "BFA", "CAF", "COD", "ERI" , "ETH", "GIN" , "GMB" , "LBR", "MDG")
                            > +///
                            3 is not a valid command name
                            r(199);

                            .
                            . 3 * inlist(countrycode, "MLI" , "MOZ", "MWI" , "NER", "RWA", "SDN", "SLE", "SOM" , "SSD" , "TCD"
                            > ) + ///
                            3 is not a valid command name
                            r(199);

                            .
                            . 3 * inlist(countrycode, "TGO", "UGA", "ZMB")
                            3 is not a valid command name
                            r(199);

                            Comment


                            • #29
                              I see two problems with the code you are trying.

                              1. GNQ appears with a closing quote but no opening quote in the first line. Add the opening quote so that quotes are balanced.

                              2. The line continuation /// must be preceded by a space on each line. As written, it is immediately following a + character, and Stata's parser does not recognize it. Add a space between + and /// on each line (except the last, of course).

                              Added: I see another problem. You are applying the -inlist()- function to string expressions, and in this situation a maximum of 10 arguments is permitted. Several of the lines in the command have 11 arguments: countrycode + 10 specific codes. So you will have to redistribute things so that at most 9 specific codes appear in each -inlist()- term.
                              Last edited by Clyde Schechter; 09 Jun 2024, 17:36.

                              Comment


                              • #30
                                Originally posted by Clyde Schechter View Post
                                I see two problems with the code you are trying.

                                1. GNQ appears with a closing quote but no opening quote in the first line. Add the opening quote so that quotes are balanced.

                                2. The line continuation /// must be preceded by a space on each line. As written, it is immediately following a + character, and Stata's parser does not recognize it. Add a space between + and /// on each line (except the last, of course).

                                Added: I see another problem. You are applying the -inlist()- function to string expressions, and in this situation a maximum of 10 arguments is permitted. Several of the lines in the command have 11 arguments: countrycode + 10 specific codes. So you will have to redistribute things so that at most 9 specific codes appear in each -inlist()- term.

                                Thanks, Clyde Schechter. I have made all the changes you have stated but the code won't work. I still get this error message.


                                .
                                . gen groups= 1 * inlist(countrycode1, "SYC", "NAM", "BWA", "GNQ", "GAB", "LBY", "MUS", "ZAF") + /
                                > //
                                invalid syntax
                                r(198);

                                .
                                . 2 * inlist(countrycode1, "AGO", "DZA", "BEN", "CIV", "CMR", "COG", "COM", "CPV", "DJI") + ///
                                2 is not a valid command name
                                r(199);

                                .
                                . 2 * inlist(countrycode, "EGY", "GHA", "KEN", "LSO", "MAR", "MRT", "NGA", "SEN", "STP") + ///
                                2 is not a valid command name
                                r(199);

                                .
                                . 2 * inlist(countrycode, "TUN", "TZA", "ZWE", "SWZ")+ ///
                                2 is not a valid command name
                                r(199);

                                .
                                . 3 * inlist(countrycode, "BDI", "BFA", "CAF", "COD", "ERI" , "ETH", "GIN" , "GMB" , "LBR" ) + ///
                                3 is not a valid command name
                                r(199);

                                .
                                . 3 * inlist(countrycode, "MLI" , "MOZ", "MWI" , "NER", "RWA", "SDN", "SLE", "SOM" , "SSD" , )+ /
                                > //
                                3 is not a valid command name
                                r(199);

                                .
                                . 3 * inlist(countrycode, "TGO", "UGA", "ZMB", "MDG" ,"TCD")
                                3 is not a valid command name
                                r(199);

                                .
                                .
                                .
                                . label def gnames ///
                                invalid syntax
                                r(198);

                                .
                                . 1 "Upper Income" ///
                                1 is not a valid command name
                                r(199);

                                .
                                . 2 " lower middle Income" ///
                                2 is not a valid command name
                                r(199);

                                .
                                . 3 "Low Income"
                                3 is not a valid command name
                                r(199);

                                .
                                . label val groups gnames
                                variable groups not found
                                r(111);

                                .
                                .
                                .
                                . label var groups "Countrycode income groups"
                                variable groups not found
                                r(111);

                                Comment

                                Working...
                                X