Announcement

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

  • copy variable labels

    Hi Statalist, apologies if I missed this question.
    I tried most suggestions on here, unfortunately I couldn't solve it.

    I have a long data of more than 100 variables. I want to generate a new variable for each of them. I wanted to copy their corresponding labels from the old variable.

    Code:
    * Example generated by -dataex-. To install: ssc install dataex
    clear
    input long GeoFips int(LineCode years) str20 GeoName str95 Description long y str6 newvar
    1000 100 1998 "Alabama" "      Forestry, fishing, and related activities" 19434 "ffr"  
    1000 100 1998 "Alabama" "      Forestry, fishing, and related activities" 19434 "ffr"  
    1000 100 1998 "Alabama" "      Forestry, fishing, and related activities" 19434 "ffr"  
    1000 100 1999 "Alabama" "      Forestry, fishing, and related activities" 18375 "ffr"  
    1000 100 1999 "Alabama" "      Forestry, fishing, and related activities" 18375 "ffr"  
    1000 100 1999 "Alabama" "      Forestry, fishing, and related activities" 18375 "ffr"  
    1000 100 2000 "Alabama" "      Forestry, fishing, and related activities" 17131 "ffr"  
    1000 100 2000 "Alabama" "      Forestry, fishing, and related activities" 17131 "ffr"  
    1000 100 2000 "Alabama" "      Forestry, fishing, and related activities" 17131 "ffr"  
    1000 100 2001 "Alabama" "      Forestry, fishing, and related activities"     . "ffr"  
    1000 100 2001 "Alabama" "      Forestry, fishing, and related activities"     . "ffr"  
    1000 100 2001 "Alabama" "      Forestry, fishing, and related activities"     . "ffr"  
    1000 100 2002 "Alabama" "      Forestry, fishing, and related activities" 16955 "ffr"  
    1000 100 2002 "Alabama" "      Forestry, fishing, and related activities" 16955 "ffr"  
    1000 100 2002 "Alabama" "      Forestry, fishing, and related activities" 16955 "ffr"  
    1000 100 2003 "Alabama" "      Forestry, fishing, and related activities" 15553 "ffr"  
    1000 100 2003 "Alabama" "      Forestry, fishing, and related activities" 15553 "ffr"  
    1000 100 2003 "Alabama" "      Forestry, fishing, and related activities" 15553 "ffr"  
    1000 100 2004 "Alabama" "      Forestry, fishing, and related activities" 16099 "ffr"  
    1000 100 2004 "Alabama" "      Forestry, fishing, and related activities" 16099 "ffr"  
    1000 100 2004 "Alabama" "      Forestry, fishing, and related activities" 16099 "ffr"  
    1000 100 2005 "Alabama" "      Forestry, fishing, and related activities" 15875 "ffr"  
    1000 100 2005 "Alabama" "      Forestry, fishing, and related activities" 15875 "ffr"  
    1000 100 2005 "Alabama" "      Forestry, fishing, and related activities" 15875 "ffr"  
    1000 100 2006 "Alabama" "      Forestry, fishing, and related activities" 15742 "ffr"  
    1000 100 2006 "Alabama" "      Forestry, fishing, and related activities" 15742 "ffr"  
    1000 100 2006 "Alabama" "      Forestry, fishing, and related activities" 15742 "ffr"  
    1000 100 2007 "Alabama" "      Forestry, fishing, and related activities" 15627 "ffr"  
    1000 100 2007 "Alabama" "      Forestry, fishing, and related activities" 15627 "ffr"  
    1000 100 2007 "Alabama" "      Forestry, fishing, and related activities" 15627 "ffr"  
    1000 100 2008 "Alabama" "      Forestry, fishing, and related activities" 15837 "ffr"  
    1000 100 2008 "Alabama" "      Forestry, fishing, and related activities" 15837 "ffr"  
    1000 100 2008 "Alabama" "      Forestry, fishing, and related activities" 15837 "ffr"  
    1000 100 2009 "Alabama" "      Forestry, fishing, and related activities" 14939 "ffr"  
    1000 100 2009 "Alabama" "      Forestry, fishing, and related activities" 14939 "ffr"  
    1000 100 2009 "Alabama" "      Forestry, fishing, and related activities" 14939 "ffr"
    I used the following code to generate the new var.
    I would like to avoid labeling each new variable by the same text already in "Description"

    Code:
    gen newvar="X"
    replace newvar="ffr" if Description=="Forestry, fishing, and related activities"
    I am avoiding writing

    Code:
    gen newvar="X"
    replace newvar="ffr" if Description=="Forestry, fishing, and related activities"
    What I wanted is to get the label of
    ffr
    to be
    Forestry, fishing, and related activities
    Last edited by Philmon Amasalu; 08 Oct 2021, 21:42. Reason: Forgot the code I tried:

  • #2
    I tried this code which I thought is close enough
    Code:
    levelsof description, local(levels)
    
    foreach l of local levels {
    gen newvar="X"
    levelsof newvar , local (levelr)
    foreach y of local levelr {
    replace `lveler'=`levels'
    }
    }
    Thank you in advance for any tip that may help!

    Comment


    • #3
      I think to tackle your question (and future questions on Statalist) effectively, we need to start with basic terminology. In Stata, a data(set) is made up of columns, which are called variables, and rows, which are called observations. In your example, you have 7 variables and 36 observations. In Stata, variables may have variable labels attached. In your example, there are no variable labels. Also, in Stata, only numeric variables may have value labels attached; value labels map numeric (integer) values to a text. There are no value labels in your example.

      Given this terminology, when you say

      I have a long data of more than 100 variables. I want to generate a new variable for each of them. I wanted to copy their corresponding labels from the old variable.
      it is not clear what you mean. You might want to say that you have one (string) variable, Descrtption, with more than 100 distinct values, and you may want to transform this variable into a numeric variable with value labels. If this is the case, then you want

      Code:
      encode Description , generate(description_numeric)
      which will yield

      Code:
      . list in 1/5
      
           +-----------------------------------------------------------------------------------------------------------------------------------------------------+
           | GeoFips   LineCode   years   GeoName                                       Description       y   newvar                         description_numeric |
           |-----------------------------------------------------------------------------------------------------------------------------------------------------|
        1. |    1000        100    1998   Alabama         Forestry, fishing, and related activities   19434      ffr   Forestry, fishing, and related activities |
        2. |    1000        100    1998   Alabama         Forestry, fishing, and related activities   19434      ffr   Forestry, fishing, and related activities |
        3. |    1000        100    1998   Alabama         Forestry, fishing, and related activities   19434      ffr   Forestry, fishing, and related activities |
        4. |    1000        100    1999   Alabama         Forestry, fishing, and related activities   18375      ffr   Forestry, fishing, and related activities |
        5. |    1000        100    1999   Alabama         Forestry, fishing, and related activities   18375      ffr   Forestry, fishing, and related activities |
           +-----------------------------------------------------------------------------------------------------------------------------------------------------+
      
      . list in 1/5 , nolabel
      
           +--------------------------------------------------------------------------------------------------------------------+
           | GeoFips   LineCode   years   GeoName                                       Description       y   newvar   descri~c |
           |--------------------------------------------------------------------------------------------------------------------|
        1. |    1000        100    1998   Alabama         Forestry, fishing, and related activities   19434      ffr          1 |
        2. |    1000        100    1998   Alabama         Forestry, fishing, and related activities   19434      ffr          1 |
        3. |    1000        100    1998   Alabama         Forestry, fishing, and related activities   19434      ffr          1 |
        4. |    1000        100    1999   Alabama         Forestry, fishing, and related activities   18375      ffr          1 |
        5. |    1000        100    1999   Alabama         Forestry, fishing, and related activities   18375      ffr          1 |
           +--------------------------------------------------------------------------------------------------------------------+
      Note that the new variable, description_numeric, has value label with the same name attached.

      Code:
      . describe description_numeric
      
                    storage   display    value
      variable name   type    format     label      variable label
      ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
      description_n~c long    %47.0g     description_numeric
      You might want to do the same with your variable GeoName.

      Perhaps, you want something else, entirely.
      Last edited by daniel klein; 09 Oct 2021, 03:17. Reason: spelling

      Comment


      • #4
        Dear daniel klein, thank you very much for your valuable advice.
        My question wasn't clear, I admit.

        What I wanted is to copy each variable labels in
        Description
        and paste each as
        variable label
        for the corresponding newly generated variable under
        newvar
        Or in short: copy
        Forestry, fishing, and related activities
        and paste as the variable label for
        ffr
        I am not sure if this could be done via foreach loop.
        I hope I made it a bit clearer now.
        Last edited by Philmon Amasalu; 09 Oct 2021, 15:29. Reason: typo (. before via )

        Comment


        • #5
          Description is one variable and, thus, can have at most one variable label.* Likewise, newvar is one variable and it can only have one variable label.

          "Forestry, fishing, and related activities" and "ffr" are (string) values. String values cannot have labels attached. I have shown how to create numeric variables with value labels attached. You have not stated why and/or how this is not what you want. Typically, you do not want string variables, as they are usually pretty useless in any kind of analysis.



          * In one of 100 possible label languages.

          Comment


          • #6
            Thank you once again. I am sorry for not making what I wanted clear. I am sorry to confuse the values with variables.
            I wanted to generate a new value that is a combination of
            ffr
            and another value, say "mining" using
            gen new_value=0.93*ffr + 0.02*mining
            .
            I don't want to use the long value "Forestry, fishing, and related activities" and it is for many string values.

            if I use
            encode Description, gen(newvar)
            , is there a way to do the maths :
            gen new_value=0.93*ffr + 0.02*miniing
            ?

            Comment


            • #7
              Actually, math (better yet: calculus) works only with numeric variables. Whether the alpha-numeric ordering of the values of Description mapped to the set 1, 2, ... will produce the results that you are seeking is another question. Probably not.

              What do you expect the result of

              Code:
              0.93*ffr
              to be?
              Last edited by daniel klein; 09 Oct 2021, 16:04.

              Comment


              • #8

                Thank you.
                0.93*frr
                would be the product of 0.93 and the year-frr value of y in my data ( y is employment levels).
                For example, 0.93*frr in 1998 would be
                0.93*19434

                Comment


                • #9
                  Well, if you want the product of 0.93 and y, then you will have to multiply

                  Code:
                  ... 0.93*y
                  I do not understand why you think this has anything to do with Description and/or its' values at all.

                  Comment


                  • #10
                    It seems like what is wanted is a reshape using newvar as the j variable to generate new variables called ffr, mining, etc., and then label those variables based on the value of Description prior to the reshape, after which an operation like -gen new_value=0.93*ffr + 0.02*mining- is plausible.

                    If the intended outcome is a dataset which looks like this:

                    Code:
                    . list
                    
                         +----------------------------------------------+
                         | GeoFips   LineCode   years   GeoName     ffr |
                         |----------------------------------------------|
                      1. |    1000        100    1998   Alabama   19434 |
                      2. |    1000        100    1999   Alabama   18375 |
                      3. |    1000        100    2000   Alabama   17131 |
                      4. |    1000        100    2001   Alabama       . |
                      5. |    1000        100    2002   Alabama   16955 |
                         |----------------------------------------------|
                      6. |    1000        100    2003   Alabama   15553 |
                      7. |    1000        100    2004   Alabama   16099 |
                      8. |    1000        100    2005   Alabama   15875 |
                      9. |    1000        100    2006   Alabama   15742 |
                     10. |    1000        100    2007   Alabama   15627 |
                         |----------------------------------------------|
                     11. |    1000        100    2008   Alabama   15837 |
                     12. |    1000        100    2009   Alabama   14939 |
                         +----------------------------------------------+
                    . desc
                    
                    Contains data
                      obs:            12                          
                     vars:             5                          
                    ------------------------------------------------------------------------------------------------------------------------
                                  storage   display    value
                    variable name   type    format     label      variable label
                    ------------------------------------------------------------------------------------------------------------------------
                    GeoFips         long    %12.0g                
                    LineCode        int     %8.0g                
                    years           int     %8.0g                
                    GeoName         str20   %20s                  
                    ffr             long    %12.0g                Forestry, fishing, and related activities
                    ------------------------------------------------------------------------------------------------------------------------
                    The following code will be of use:

                    Code:
                    duplicates drop
                    preserve
                    collapse (first) Description,by(newvar)
                    forval x = 1/`=_N'{
                        local labely`=newvar[`x']' `=Description[`x']'
                    }
                    restore
                    drop Description
                    reshape wide y, i(GeoFips LineCode GeoName years) j(newvar,string)
                    local vars: char _dta[ReS_Xij_wide1]
                    foreach var of varlist `vars'{
                        label variable `var' "`label`var''"
                        rename y`=substr("`var'",2,strlen("`var'")-1)' `=substr("`var'",2,strlen("`var'")-1)'
                    }
                    Last edited by Ali Atia; 09 Oct 2021, 17:32.

                    Comment


                    • #11
                      Thank you again.
                      Code:
                      * Example generated by -dataex-. To install: ssc install dataex
                      clear
                      input str20 GeoName long GeoFips int years long(y100 y101 y102 y103 y200 y201 y202 y203 y300 y400 y401 y402 y403 y500)
                      "Alabama"    1000 1998  19434 10193     .   7204 11760  1804  8377  1579 14467  150643  35912  18060  96671  371319
                      "Alabama"    1000 1999  18375  9637     .   6841 10816  1752  7804  1260 14485  154368  36979  18756  98633  361668
                      "Alabama"    1000 2000  17131  8852  1816   6463  9439  1636  6826   977 14522  156466  37196  19278  99992  353784
                      "Alabama"    1000 2001      .     .  1631   6093  9508  1864  6679   965 14604  158892  39363  20340  99189  335261
                      "Alabama"    1000 2002  16955  8347  1894   6714  9269  1715  6606   948 14177  152592  37855  19645  95092  315019
                      "Alabama"    1000 2003  15553  7929  1416   6208  9107  1986  6239   882 13841  155592  35462  19024 101106  299642
                      "Alabama"    1000 2004  16099  8222  1577   6300  9109  1833  6294   982 13791  162580  36967  19052 106561  298438
                      "Alabama"    1000 2005  15875  8187  1579   6109  9898  2021  6753  1124 13150  171349  40082  20225 111042  306074
                      "Alabama"    1000 2006  15742  8124  1612   6006 10408  2264  6945  1199 13353  178731  41096  21768 115867  309950
                      "Alabama"    1000 2007  15627  7800  1590   6237 10678  2355  6966  1357 13816  183410  41572  22488 119350  304225
                      "Alabama"    1000 2008  15837  7850  1554   6433 11666  3212  7077  1377 14538  174418  39066  20993 114359  290233
                      "Alabama"    1000 2009  14939  7056  1513   6370 10928  3140  6644  1144 14247  153203  34058  19119 100026  254643
                      "Alabama"    1000 2010  14901  6741  1877   6283 11996  4002  6861  1133 14551  143646  31714  19330  92602  244202
                      "Alabama"    1000 2011  14987  6962  1700   6325 11931  3459  7256  1216 14590  138907  29428  18553  90926  246344
                      "Alabama"    1000 2012  15773  7728  1651   6394 14009  4334  8205  1470 14569  136841  30519  18645  87677  252491
                      "Alabama"    1000 2013  16022  7970  1653   6399 13629  4953  7261  1415 14699  135665  30508  18151  87006  258984
                      "Alabama"    1000 2014  16526  7843  1653   7030 13042  4816  6865  1361 14677  135625  29680  18601  87344  262500
                      "Alabama"    1000 2015  16141  8059  1459   6623 12995  4930  6753  1312 14960  136107  31912  18363  85832  267881
                      "Alabama"    1000 2016  16094  7892  1606   6596 11458  5062  5298  1098 14961  141701  32082  19233  90386  271192
                      "Alabama"    1000 2017  15637  7106  1485   7046 10431  3109  6019  1303 14138  142525  31515  20372  90638  274115
                      "Alabama"    1000 2018  15929  7007  1562   7360  9641  2543  5854  1244 14259  148034  33355  20759  93920  277594
                      "Alabama"    1000 2019  16316  7131  1589   7596  9172  2186  5826  1160 13756  152444  34804  20646  96994  279250
                      "Alabama"    1000 2020  15724  6788  1766   7170  8513  2032  5419  1062 13572  150304  34209  19835  96260  268115
                      "Alaska"     2000 1998  16295  1397 14399      . 12691  3388  2890  6413  1636   21151   6101   3236  11814   15223
                      "Alaska"     2000 1999  14896  1455 12996      . 10892  3187  2717  4988  1674   21246   6205   2944  12097   13839
                      "Alaska"     2000 2000  14077  1307 12372      . 11623  3031  2715  5877  1677   21337   6094   3171  12072   13761
                      "Alaska"     2000 2001      .   986     .      .     .  3287     .  6695  1691   22339   6410   3342  12587   14326
                      "Alaska"     2000 2002  13382   858     .      . 11674  3081  2464  6129  1840   23382   6801   3427  13154   13071
                      "Alaska"     2000 2003  10825   800  9605    420 11209  2903  2641  5665  1885   24881   7328   3646  13907   13289
                      "Alaska"     2000 2004  12197     . 11057      . 10994  2829  2301  5864  1900   25975   7533   3874  14568   14020
                      "Alaska"     2000 2005  12497   790 11259    448 11573  2934  2284  6355  1936   27240   8006   4093  15141   14419
                      "Alaska"     2000 2006  12334   623     .      . 13490  3207  2645  7638  1945   26868   7770   4429  14669   15105
                      "Alaska"     2000 2007  12025   520     .      . 15829  3565  3576  8688  1970   26484   7715   4188  14581   15372
                      "Alaska"     2000 2008  12220   460     .      . 17386  4057  3647  9682  2068   25817   7251   4208  14358   15038
                      "Alaska"     2000 2009  11574   440 10602    532 16941  4086  3469  9386  2092   24690   6882   4127  13681   15295
                      "Alaska"     2000 2010  12004     . 11017      . 17782  4187  4188  9407  2262   24026   6632   4143  13251   14940
                      "Alaska"     2000 2011  11428     . 10427      . 18287  4164  4554  9569  2191   23478   6515   3816  13147   16078
                      "Alaska"     2000 2012  11350   505 10385    460 21643  4628  6942 10073  2209   23997   6510   4131  13356   16459
                      "Alaska"     2000 2013  12043   501 11101    441 21153  4918  6002 10233  2237   24118   6411   4400  13307   17044
                      "Alaska"     2000 2014  12140   525 11120    495 21557  5064  5717 10776  2210   24718   6353   5002  13363   16910
                      "Alaska"     2000 2015  10193   534  9223    436 21130  4969  5794 10367  2280   25016   6578   5304  13134   16719
                      "Alaska"     2000 2016  10251   503  9302    446 18650  4701  6089  7860  2347   23939   6147   4993  12799   16440
                      "Alaska"     2000 2017  10004     .  9063      . 17185  4211  6367  6607  2237   22680   5940   4615  12125   16071
                      "Alaska"     2000 2018  10406   450     .      . 15278  3994  5068  6216  2321   23285   6264   4890  12131   15384
                      "Alaska"     2000 2019  11103   465 10108    530 15310  3947  4674  6689  2324   23498   6607   4892  11999   15547
                      "Alaska"     2000 2020      .   457 10560      . 13181  3592  4755  4834  2431   22930   6618   4525  11787       .
                      "Arizona"    4000 1998  19718   598     .  18427 16175     . 13359   493  9881  187428  34563  22682 130183  220487
                      "Arizona"    4000 1999  19285     .     .  18138 14160     . 11346   511 10393  198267  36862  24620 136785  217168
                      "Arizona"    4000 2000  17561     .     .  16471 12630     . 10005   488 10773  206507  38953  27081 140473  219420
                      "Arizona"    4000 2001  18083     .     .  17120 12919  2405 10161   353 11233  214418  41399  28638 144381  211028
                      "Arizona"    4000 2002  18949     .     .  17947 11662  2080  9076   506 11317  213386  40813  31748 140825  193778
                      "Arizona"    4000 2003  17659     .     .  16778 11717     .  8572     . 11684  220988  41267  28134 151587  185806
                      "Arizona"    4000 2004  18017   363   616  17038 11603     .  8807     . 11726  239849  44693  27624 167532  186909
                      "Arizona"    4000 2005  17227     .     .  16158 12508  3038  8913   557 12130  273970  51736  31061 191173  190478
                      "Arizona"    4000 2006  17503     .     .  16470 13698  2918 10185   595 12740  297178  57613  32384 207181  195723
                      "Arizona"    4000 2007  17526     .     .  16530 16208  2970 12371   867 13181  282613  53421  31763 197429  193259
                      "Arizona"    4000 2008  16486     .     .  15498 19114  4492 13512  1110 13297  240419  46614  28980 164825  183747
                      "Arizona"    4000 2009  14828   318   608  13902 16520     . 10712     . 12844  179765  34635  21114 124016  165325
                      "Arizona"    4000 2010  15508     .     .  14596 17976  6024 10866  1086 12515  159503  30850  18556 110097  158837
                      "Arizona"    4000 2011  15642   298   587  14757 17698  5158 11553   987 12256  159458  30334  18507 110617  161619
                      "Arizona"    4000 2012  15281     .     .  14323 22558  7492 13777  1289 12607  165892  31625  18941 115326  166685
                      "Arizona"    4000 2013  15233   388   685  14160 23098  8169 13893  1036 12282  174505  32845  19805 121855  168502
                      "Arizona"    4000 2014  15919     .     .  14813 22309  7753 13440  1116 12337  176274  32436  19208 124630  169370
                      "Arizona"    4000 2015  16550     .     .  15404 22499  8380 13014  1105 12657  178896  34963  18232 125701  171753
                      "Arizona"    4000 2016  16388     .     .  15144 22709  8681 12853  1175 13260  191362  37485  18360 135517  175188
                      "Arizona"    4000 2017  15948     .     .  14763 21428  6603 13550  1275 12899  203323  40209  19505 143609  178653
                      "Arizona"    4000 2018  15976   415   774  14787 20056  4998 13808  1250 12760  219947  45291  20999 153657  184541
                      "Arizona"    4000 2019  15624   385   829  14410 19193  4374 13675  1144 12959  234494  47909  22963 163622  191002
                      "Arizona"    4000 2020  14402   379   884  13139 17746  4144 12597  1005 12640  234931  47961  23075 163895  190143
                      "Arkansas"   5000 1998  17495  7248     .   9201  6843  3231  2338  1274  7158   84941  18997  10871  55073  243383
                      "Arkansas"   5000 1999  16910  7266     .   8706  6496  3106  2321  1069  7048   86516  20004  11496  55016  241210
                      "Arkansas"   5000 2000  15960  6662     .   8405  6242  2873  2206  1163  6959   89025  21090  12581  55354  240220
                      "Arkansas"   5000 2001  15147  6087   765   8295  7051  3202  2348  1501  6996   91105  20473  14534  56098  231336
                      "Arkansas"   5000 2002  15938     .     .   8929  6416  2853  2216  1347  6926   90786  19963  15872  54951  218261
                      "Arkansas"   5000 2003  14380  5716   703   7961  7172  3510  2166  1496  6855   89392  18833  12884  57675  210090
                      "Arkansas"   5000 2004  14971     .     .   8325  7046  3121  2267  1658  6685   92584  19633  12527  60424  207945
                      "Arkansas"   5000 2005  14899  5949   890   8060  7404  3301  2157  1946  6788   99535  21653  13099  64783  205415
                      "Arkansas"   5000 2006  14443     .     .   7941  8842  3876  2327  2639  7030  102421  22804  13256  66361  203171
                      "Arkansas"   5000 2007  14425     .     .   8250 11242  4218  2590  4434  7213  101248  22124  12812  66312  193681
                      "Arkansas"   5000 2008  14360  5095   856   8409 14800  6498  2637  5665  7288   98172  21709  13177  63286  186262
                      "Arkansas"   5000 2009  13704  4408   836   8460 14775  6785  2366  5624  7271   91831  19871  12503  59457  166722
                      "Arkansas"   5000 2010  13899  4160   826   8913 16781  8625  2572  5584  7539   86153  17155  12964  56034  162730
                      "Arkansas"   5000 2011  13876  4229   791   8856 15825  7557  2605  5663  7349   84959  16498  12184  56277  162402
                      "Arkansas"   5000 2012  14517     .     .   8994 18604  9986  3086  5532  7896   85017  17421  11242  56354  159500
                      "Arkansas"   5000 2013  14435     .     .   8839 18087 10887  2624  4576  8292   82686  16655  10155  55876  157605
                      "Arkansas"   5000 2014  14750     .     .   9295 17110 10575  2499  4036  8109   83413  16834  10135  56444  158469
                      "Arkansas"   5000 2015  14379     .     .   8715 16750 10842  2594  3314  8248   85161  18823   9920  56418  160559
                      "Arkansas"   5000 2016  14512  4890   856   8766 15755 11163  2611  1981  8176   88652  18600  10225  59827  160972
                      "Arkansas"   5000 2017  14488  4405   790   9293 13236  8423  2852  1961  7981   89895  18283  11641  59971  163437
                      "Arkansas"   5000 2018  14761  4526   858   9377 10586  6266  2544  1776  8064   90641  19253  10654  60734  166358
                      "Arkansas"   5000 2019  14404  4378   924   9102  9493  5511  2327  1655  8131   92255  19477  10594  62184  167828
                      "Arkansas"   5000 2020  14272  4288   975   9009  8935  5186  2361  1388  8166   92051  19257  10554  62240  160231
                      "California" 6000 1998 204801  7200  8083 189518 40010 21264  9372  9374 59342  900026 209364  85671 604991 1941979
                      "California" 6000 1999 201514  7273  7373 186868 37011 19768  9471  7772 58719  964211 229824  90936 643451 1901807
                      "California" 6000 2000 198941  6208  6632 186101 35347 17928  9081  8338 57477  996906 238863  94116 663927 1919727
                      "California" 6000 2001 189802  6139  5656 178007 38072 19851  9346  8875 56349 1063103 253790  99322 709991 1867740
                      "California" 6000 2002 190942  5917  6211 178814 33442 17716  8010  7716 56329 1052033 258651 103223 690159 1720515
                      "California" 6000 2003 191150  5340  4910 180900 35915 20341  8017  7557 56949 1087203 253788 100916 732499 1615130
                      "California" 6000 2004 190783  5545  5351 179887 34381 18962  7726  7693 57734 1167793 271151 101180 795462 1601392
                      "California" 6000 2005 200827  5776  5153 189898 36328 20139  7715  8474 57637 1248701 296463 105665 846573 1582808
                      end

                      I reshaped my data to wide so that all the industry employment are on columns and I can generate new variables as combination of any of them.
                      gen ffr=0.93*y100+0.07*y102
                      renaming each industry employment (110 here) and labeling each is daunting.
                      Advise me if there is a way to avoid this.
                      My earlier question was : to do the same task wile data is still in long format.

                      Comment


                      • #12
                        Ali Atia, thank you very much. I did not ask my question the way you did, apologies daniel klein
                        Yes, it was to ask what you did above and your code works.

                        Comment

                        Working...
                        X