Announcement

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

  • names and labels

    I collapsed my variables but I want to keep the original labels while keeping the "mean" on the variable names.

    -collapse vb_1 vb_2 vb_3, by( country_name)-

    Code:
    * Example generated by -dataex-. To install: ssc install dataex
    clear
    input str30 country_name double(vb_1 vb_2 vb_3)
    "Algeria"                         6.914386526 31.423809597142867 28.671428680952378
    "Angola"                    4.021512833166667 20.880952290476188  52.87619055000001
    "Benin"                    17.292362279350005  7.442857242761906 11.580952304047617
    "Botswana"                  6.317734659809524 12.976190476142861  23.35238084333333
    "Burkina Faso"             11.153648083095238  2.842857116809524  5.514285655190478
    "Burundi"                  10.712366176904762  .9333333201904762  4.428571473904761
    "Cabo Verde"                                .  1.190476213333333 15.504762058571426
    "Cameroon"                      16.2278944605  7.071428548714285  10.26190480704762
    "Central African Republic"  6.683741986800001  .9238095055238096  7.490476199571429
    "Chad"                      5.004593229285713  .7428571468571429  2.947619052190476
    "Comoros"                                   .  .5238095295238094  7.190476190571429
    "Congo, Dem. Rep."          16.63919887066667  1.904761899142857  9.500000000000002
    "Congo, Rep."               4.965421424047618 27.480952579999997  24.40952355619047
    "Cote d'Ivoire"                 14.6325414675  .7999999862857143  7.542857170142857
    "Djibouti"                 2.6505125769166664  31.36666661190476 17.566666467619047
    "Egypt, Arab Rep."         17.470223347619047 6.7761905080952385  26.65238089809524
    "Equatorial Guinea"        11.922694508454548  4.619047607714284 24.342857179000003
    "Eritrea"                   8.593188423928572  .9714285645714286 11.552381060952381
    "Ethiopia"                  5.179430505666666 10.766666594142855  11.99047617685714
    "Gabon"                    3.9761472838000005  4.366666646190477   23.4904762447619
    "Gambia, The"               5.738909381923078 1.9857142652857145 15.700000036238093
    "Ghana"                     8.379223804333332 12.871428625714284 14.828571365238096
    "Guinea"                         4.6514094998 1.1238095306666667  9.919047537523808
    "Guinea-Bissau"                  9.6552097125  .9619047641904762  9.033333301523808
    "Kenya"                    12.121018557619047 2.7523809276190474 11.666666576190474
    "Lesotho"                  17.307661698428568 15.847619101857143 16.276190530523806
    "Liberia"                        4.7200937698 3.8333333618095233 11.452380906952381
    "Libya"                     4.675274085428571 23.180952344761902        25.96666654
    "Madagascar"               12.809202575384615  3.876190469428571  8.128571442095238
    "Malawi"                   12.235083278095233 1.0761904944761906 7.9952380544285715
    "Mali"                                      . 13.300000009047618 15.895238285238095
    "Mauritania"                9.621215310952382 1.3761904807619048 11.800000054285713
    "Mauritius"                19.156800024761903 27.123809633809525  33.32857086428572
    "Morocco"                  18.594831523333333 18.723809469523808  20.39047613619048
    "Mozambique"                13.53315958314286 .28095239052380955 7.8095238322857155
    "Namibia"                  12.530266139666667  6.942857197285713 19.923809324761905
    "Niger"                                     .  23.11904752857143  9.171428634857142
    "Nigeria"                   5.200190875761906 13.061904725619048 12.190476190523812
    "Norway"                     9.27235620242857  8.271428653047618  32.59047635380952
    "Rwanda"                    6.306928253166667  1.123809522095238  8.519047555619048
    "Sao Tome and Principe"     7.939002052999999  4.685714278999999 21.742857070476187
    "Senegal"                  15.161831050526315  8.461904798190474 22.842856817142852
    "Seychelles"               13.707101198526319                  .                  .
    "Sierra Leone"             3.0255933534761903 2.4571428751904762  10.73809532857143
    "Somalia"                                   .  .8999999788571429  6.309523809476188
    "South Africa"              16.64539160428571 11.842857133809522 34.042857214761895
    "South Sudan"                               .                  .                  .
    "Sudan"                    7.3898895607499995 30.352381115238092 16.533333279047618
    "Tanzania"                   7.86577079509524 2.2428571496666665  6.585714249238096
    "Togo"                      7.746418947095239  5.819047609857143 10.857142902380952
    "Tunisia"                   18.00225670333334 36.290475935238085 27.214285714285708
    "Uganda"                    8.642488205238095  4.723809560190476  9.785714285476193
    "Zambia"                          9.780431086  3.104761907095238 12.385714213285713
    "Zimbabwe"                 14.250724051809524  4.028571401333333 15.447618893809524
    end

  • #2
    Variable labels? None are visible in your example.

    Comment


    • #3
      dataex does'nt capture the labels for me to copy. How do i get the labels included in example?

      Code:
      * Example generated by -dataex-. To install: ssc install dataex
      clear
      input double(vb_1 vb_2 vb_3)
      14.32308799           .           .
      15.16711296           .           .
      17.21017755           .           .
      16.99969357           .           .
      16.27246759           .           .
      16.51608947           .           .
       8.99254138           .           .
      9.691966938           .           .
      10.66747203           .           .
      10.37953348           .           .
      11.75426056           .           .
      11.47035574           .           .
      10.55408935           .           .
      10.59490047           .           .
       11.1516422           .           .
      11.80587996           .           .
      13.82716047           .           .
      13.69914188           .           .
      15.70853213           .           .
      14.88419564           .           .
      14.88895829           .           .
      12.32032899           .           .
      11.37795243           .           .
      11.44609737 36.20000076 23.29999924
      12.31277714 35.79999924 23.70000076
      13.13449375 36.09999847 24.10000038
      12.35938602 36.70000076 24.20000076
      11.49787293 35.90000153 24.10000038
       9.03892537        32.5 23.10000038
       8.72045298        31.5 22.89999962
      9.909318814          32 23.89999962
      8.977644334        31.5 23.79999924
      7.539511501 29.79999924 23.39999962
                . 29.10000038 23.70000076
                . 27.60000038 24.10000038
                . 25.60000038 23.79999924
                . 29.39999962 25.60000038
                .        29.5 26.70000076
                .          30 27.79999924
                . 30.39999962 29.29999924
                . 31.39999962        30.5
                . 34.20000076        33.5
                . 33.90000153 33.90000153
      4.836015431          31          33
       4.82097761          33 33.90000153
      5.008916922 33.90000153        34.5
      5.240150427 34.29999924 34.90000153
      5.893805499          35 35.09999847
      6.072532898 34.29999924 34.70000076
                . 34.20000076 34.59999847
                .           .           .
                .           .           .
                .           .           .
                .           .           .
                .           .           .
                .           .           .
                .           .           .
                .           .           .
                .           .           .
                .           .           .
                .           .           .
                .           .           .
                .           .           .
                .           .           .
                .           .           .
                .           .           .
                .           .           .
       9.86950016           .           .
      10.38399982           .           .
      8.076000214           .           .
      9.836500168           .           .
      5.688333511           .           .
      5.118000031           .           .
             12.5        22.5 52.20000076
      3.846153846        21.5 51.79999924
      5.576208178 23.60000038          54
      4.950016124 25.89999962 53.70000076
      4.007465964 24.79999924 54.70000076
      3.445749994 24.79999924 54.90000153
      4.378391184        23.5 54.29999924
      6.318795907 23.70000076 57.09999847
      3.222875779 25.39999962 53.29999924
      2.890163321 24.89999962 49.70000076
      3.873100814        23.5 52.70000076
                . 20.70000076 53.29999924
                . 20.29999924          53
                .          20 53.29999924
                . 20.39999962 52.59999847
                .          20 53.40000153
                . 19.60000038 52.29999924
                . 19.29999924 51.20000076
                . 17.79999924 51.29999924
                . 19.10000038 52.79999924
                . 19.70000076          52
                . 19.79999924          54
                . 18.89999962 52.90000153
                . 19.20000076 52.40000153
                . 18.89999962 51.90000153
                .          19          52
                .          19 52.40000153
      end

      Comment


      • #4
        You need extra code such as you would use in defining them in the first place.

        Comment


        • #5
          I'm not sure I understand, Is there a link for further reading please?

          Comment


          • #6
            Code:
            help label
            #1 and #3 don't allow discussion of the problem because there are no variable labels.

            Nevertheless, the first result from

            Code:
            . search collapse , faq
            
            Search of official help files, FAQs, Examples, SJs, and STBs
            
            FAQ     . . . . . . . . . . . . Keeping the same variable labels with collapse
                    . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .  N. J. Cox
                    2/03    How can I collapse my dataset and keep the same
                            variable labels?
                            http://www.stata.com/support/faqs/data-management/
                            keeping-same-variable-with-collapse/
            may be what you seek.

            help and search are your friends! Note also the start of https://www.statalist.org/forums/help#before

            3. What should I do before I post?

            Before posting, consider other ways of finding information:
            • the online help for Stata
            • Stata's search command, which can tell you about all built-in Stata commands, all ado-files published in the Stata Journal, all FAQs on the Stata website, www.stata.com, and user-written Stata programs available on the Internet (if you have Stata 12 or earlier, you can use findit to search all these sources at once)
            Last edited by Nick Cox; 29 Mar 2018, 11:05.

            Comment

            Working...
            X