Announcement

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

  • syntax for an equation

    Dear all,

    First of all, I do apologize that my question does not have a dataset.
    I am going to compute this question.
    Click image for larger version

Name:	eq.PNG
Views:	1
Size:	3.9 KB
ID:	1698317
    This is the information:
    t= 2010-2021
    d=7 (Norte, Centro, Lisboa, Alentejo, Algarve, Açores, Madeira)
    o= (SP, FR, IT, UK, Ukr, RO, MO, OtherEU, AN, CP, GB, MO, SDP, OtherAF, BR, OtherUS, CH, IN, NE, OtherAS)


    Any ideas/solutions would be appreciated.

  • #2
    It’s impossible to give you any kind of answer without knowing how your data are structured. To see that, you are asked to provide a data example and possibly explanation of what you are trying to compute, which you have simply ignored.

    A reasonable solution would require multiple commands of the form: bysort … : egen.

    Comment


    • #3
      Dear Guizetti, You are completely right.
      I allocate the total number of immigrants in Portugal at time t from a given origin 'o', IMo,t--in proportion to the share of that national group in the district as of 1981.By summing across countries of origin 'o' I am going to obtain an imputed number of immigrants in each district:


      Code:
      * Example generated by -dataex-. For more info, type help dataex
      clear
      input str29 Districts int(year Spain France tot_SP tot_FR)
      "Norte"                         1981 1602 5286 8081 12079
      "Centro"                        1981  672 3814    .     .
      "Área Metropolitana de Lisboa" 1981 4921 1858    .     .
      "Alentejo"                      1981  625  422    .     .
      "Algarve"                       1981  194  449    .     .
      "Região Autónoma dos Açores" 1981   35   47    .     .
      "Região Autónoma da Madeira"  1981   32  203    .     .
      end

      and


      Code:
      * Example generated by -dataex-. For more info, type help dataex
      clear
      input str29 Districts int(Spain C D E F G H I J K L M France O P Q R S T U V W X Y)
      "Norte"                         2010 2011 2012 2013 2014 2015 2016 2017 2018 2019 2020 2021 2010 2011 2012 2013 2014 2015 2016 2017 2018  2019  2020  2021
      "Centro"                        2750 2784 2770 2649 2524 2496 2620 2712 2980 3223 3639 4088  992 1011  971  976 1032 1152 1363 1663 2097  2384  2648  2960
      "Área Metropolitana de Lisboa" 1171 1216 1279 1327 1264 1333 1465 1489 1608 1769 1889 2129 1024 1048 1060 1066 1156 1305 1542 1880 2277  2724  3046  3331
      "Alentejo"                      3524 3693 3650 3835 4082 4307 5049 6139 7061 8222 8645 9191 1712 1829 1806 1865 2519 3301 4696 6916 9411 11207 12076 12966
      "Algarve"                        543  619  651  657  689  686  671  669  695  716  777  825  221  243  237  214  237  283  320  377  449   499   533   577
      "Região Autónoma dos Açores"  661  709  701  716  748  786  882 1035 1198 1369 1463 1673  916  905  856  870 1307 2075 3014 4069 5096  5837  6133  6328
      "Região Autónoma da Madeira"   131  159  165  221  252  265  269  267  238  226  234  279   80   95   99  119  124  134  149  170  168   166   178   193
      ""                               138  130  135  136  133  146  177  215  286  323  334  361  166  162  172  158  166  190  209  244  273   308   321   364
      end
      Last edited by Paris Rira; 23 Jan 2023, 15:29.

      Comment


      • #4
        Apparently your IMdd,o,1981 data are something like
        Code:
        * Example generated by -dataex-. For more info, type help dataex
        clear
        input str29 Districts int year float(Spain France)
        "Norte"                         1981 1602 5286
        "Centro"                        1981  672 3814
        "Área Metropolitana de Lisboa"  1981 4921 1858
        "Alentejo"                      1981  625  422
        "Algarve"                       1981  194  449
        "Região Autónoma dos Açores"    1981   35   47
        "Região Autónoma da Madeira"    1981   32  203
        end
        Starting with that data
        Code:
        * insert appropriate command to read data here
        rename (Spain-France) (IM=)
        reshape long IM, i(Districts) j(Country) string
        sort Country Districts
        by Country: egen TotIM = total(IM)
        generate IMshare = IM/TotIM
        format %9.3f IMshare
        list, clean noobs
        drop year TotIM
        save shares1981, replace
        creates a dataset containing the district shares for each national group in 1981.
        Code:
        . list, clean noobs
        
                               Districts   Country   year     IM   TotIM   IMshare  
                                Alentejo    France   1981    422   12079     0.035  
                                 Algarve    France   1981    449   12079     0.037  
                                  Centro    France   1981   3814   12079     0.316  
                                   Norte    France   1981   5286   12079     0.438  
              Região Autónoma da Madeira    France   1981    203   12079     0.017  
              Região Autónoma dos Açores    France   1981     47   12079     0.004  
            Área Metropolitana de Lisboa    France   1981   1858   12079     0.154  
                                Alentejo     Spain   1981    625    8081     0.077  
                                 Algarve     Spain   1981    194    8081     0.024  
                                  Centro     Spain   1981    672    8081     0.083  
                                   Norte     Spain   1981   1602    8081     0.198  
              Região Autónoma da Madeira     Spain   1981     32    8081     0.004  
              Região Autónoma dos Açores     Spain   1981     35    8081     0.004  
            Área Metropolitana de Lisboa     Spain   1981   4921    8081     0.609
        And, since I do not understand your second example data, apparently your IMo,t data are something like
        Code:
        * Example generated by -dataex-. For more info, type help dataex
        clear
        input str6 Country int Year float IM
        "France" 2010 5000
        "France" 2011 5200
        "France" 2012 5100
        "Spain"  2010 8900
        "Spain"  2011 9300
        "Spain"  2012 9300
        end
        So then continuing with this country data, we add to the the code above
        Code:
        * insert appropriate command to read data here 
        joinby Country using shares1981
        sort Country Districts
        generate IMdistrict = IM*IMshare
        format %9.1f IMdistrict
        list if Year==2010, sepby(Country) abbreviate(16)
        and we see results like those you seek.
        Code:
        . list if Year==2010, sepby(Country) abbreviate(16)
        
             +-----------------------------------------------------------------------------+
             | Country   Year     IM                      Districts   IMshare   IMdistrict |
             |-----------------------------------------------------------------------------|
          2. |  France   2010   5000                       Alentejo     0.035        174.7 |
          6. |  France   2010   5000                        Algarve     0.037        185.9 |
          9. |  France   2010   5000                         Centro     0.316       1578.8 |
         11. |  France   2010   5000                          Norte     0.438       2188.1 |
         13. |  France   2010   5000     Região Autónoma da Madeira     0.017         84.0 |
         16. |  France   2010   5000     Região Autónoma dos Açores     0.004         19.5 |
         21. |  France   2010   5000   Área Metropolitana de Lisboa     0.154        769.1 |
             |-----------------------------------------------------------------------------|
         24. |   Spain   2010   8900                       Alentejo     0.077        688.3 |
         27. |   Spain   2010   8900                        Algarve     0.024        213.7 |
         29. |   Spain   2010   8900                         Centro     0.083        740.1 |
         33. |   Spain   2010   8900                          Norte     0.198       1764.4 |
         34. |   Spain   2010   8900     Região Autónoma da Madeira     0.004         35.2 |
         39. |   Spain   2010   8900     Região Autónoma dos Açores     0.004         38.5 |
         42. |   Spain   2010   8900   Área Metropolitana de Lisboa     0.609       5419.7 |
             +-----------------------------------------------------------------------------+

        Comment


        • #5
          Dear William, Thanks a million. That's what I need.

          now, since its a shift-share instrument variable computation, I am going to obtain one number according to question, # 1, may I do:

          Code:
          collapse (sum) IMdistrict

          Comment


          • #6
            I'm not an economist, much less an econometrician, so I have no knowledge of or experience with instrumental variable methodologies.

            It seems to me the collapse command you propose will yield a single number which will be the total immigration into Portugal from all the sources into all the districts across all the years. Is that what you need?

            Comment


            • #7
              Originally posted by William Lisowski View Post
              I'm not an economist, much less an econometrician, so I have no knowledge of or experience with instrumental variable methodologies.
              But you are a master in state. I guess there are some other fields dealing with state then.

              Originally posted by William Lisowski View Post
              It seems to me the collapse command you propose will yield a single number which will be the total immigration into Portugal from all the sources into all the districts across all the years. Is that what you need?
              I am going to obtain an imputed number of immigrants in each district (7 districts) for 12 years.

              Comment


              • #8
                Ah, yes, I was so glad to get the bits and pieces that I forgot the grand summation to calculate IMhatd,t.
                Code:
                . collapse (sum) IMdistrict, by(Districts Year)
                
                . list, sepby(Districts) abbreviate(16) noobs
                
                  +--------------------------------------------------+
                  | Year                      Districts   IMdistrict |
                  |--------------------------------------------------|
                  | 2010                       Alentejo        863.0 |
                  | 2011                       Alentejo        901.0 |
                  | 2012                       Alentejo        897.5 |
                  |--------------------------------------------------|
                  | 2010                        Algarve        399.5 |
                  | 2011                        Algarve        416.6 |
                  | 2012                        Algarve        412.8 |
                  |--------------------------------------------------|
                  | 2010                         Centro       2318.9 |
                  | 2011                         Centro       2415.3 |
                  | 2012                         Centro       2383.7 |
                  |--------------------------------------------------|
                  | 2010                          Norte       3952.5 |
                  | 2011                          Norte       4119.3 |
                  | 2012                          Norte       4075.5 |
                  |--------------------------------------------------|
                  | 2010     Região Autónoma da Madeira        119.3 |
                  | 2011     Região Autónoma da Madeira        124.2 |
                  | 2012     Região Autónoma da Madeira        122.5 |
                  |--------------------------------------------------|
                  | 2010     Região Autónoma dos Açores         58.0 |
                  | 2011     Região Autónoma dos Açores         60.5 |
                  | 2012     Região Autónoma dos Açores         60.1 |
                  |--------------------------------------------------|
                  | 2010   Área Metropolitana de Lisboa       6188.8 |
                  | 2011   Área Metropolitana de Lisboa       6463.2 |
                  | 2012   Área Metropolitana de Lisboa       6447.8 |
                  +--------------------------------------------------+

                Comment


                • #9
                  I am also happy and more surprised, how did you figure out those messy data! Really appreciated for taking the time to do that.

                  Comment

                  Working...
                  X