Announcement

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

  • Generate New Variable

    Hello,

    Can somebody help me create a dummy variable?
    I want to create a variable that is =1 if a reseracher has published in "Journal of population economics" in a certain year, and 0 otherwise.

    Here is an example of the dataset I have: (Variable names are self explanatory)

    Code:
    * Example generated by -dataex-. To install: ssc install dataex
    clear
    input float Reseracher int Year long Publication str66 Channel
     35 2006  33963 "Daidalos"                                
     26 2009  43695 "Jurist- og Økonomforbundets Forlag"     
     26 2009  43696 "Jurist- og Økonomforbundets Forlag"     
     11 2006  53503 "Routledge"                               
     65 2006  53503 "Routledge"                               
     66 2006  54032 "Fagbokforlaget"                          
     65 2006  54473 "Fagbokforlaget"                          
      5 2006  54923 "Abstrakt forlag"                         
     65 2006  55447 "Fagbokforlaget"                          
     31 2006  55447 "Fagbokforlaget"                          
    114 2005  59866 "Springer-Verlag"                         
     26 2004  67831 "Fagbokforlaget"                          
     92 2008 336163 "Journal of Economic Dynamics and Control"
    114 2008 337356 "Optimization"                            
    109 2008 337381 "Journal of Population Economics"         
     31 2008 337381 "Journal of Population Economics"         
    114 2008 337433 "Journal of Economic Dynamics and Control"
     90 2008 337433 "Journal of Economic Dynamics and Control"
     78 2010 338899 "Acta Neurologica Scandinavica"           
     92 2010 339254 "Health Policy"                           
    end

  • #2
    Code:
    * Example generated by -dataex-. To install: ssc install dataex
    clear
    input float Reseracher int Year long Publication str66 Channel
     35 2006  33963 "Daidalos"                                
     26 2009  43695 "Jurist- og Økonomforbundets Forlag"     
     26 2009  43696 "Jurist- og Økonomforbundets Forlag"     
     11 2006  53503 "Routledge"                               
     65 2006  53503 "Routledge"                               
     66 2006  54032 "Fagbokforlaget"                          
     65 2006  54473 "Fagbokforlaget"                          
      5 2006  54923 "Abstrakt forlag"                         
     65 2006  55447 "Fagbokforlaget"                          
     31 2006  55447 "Fagbokforlaget"                          
    114 2005  59866 "Springer-Verlag"                         
     26 2004  67831 "Fagbokforlaget"                          
     92 2008 336163 "Journal of Economic Dynamics and Control"
    114 2008 337356 "Optimization"                            
    109 2008 337381 "Journal of Population Economics"         
     31 2008 337381 "Journal of Population Economics"         
    114 2008 337433 "Journal of Economic Dynamics and Control"
     90 2008 337433 "Journal of Economic Dynamics and Control"
     78 2010 338899 "Acta Neurologica Scandinavica"           
     92 2010 339254 "Health Policy"                           
    end
    
    egen wanted = max(Channel == "Journal of Population Economics"), by(Rese Year)
    
    sort Rese Year 
    
    list, sepby(Rese Year)
    
         +--------------------------------------------------------------------------------+
         | Resera~r   Year   Public~n                                    Channel   wanted |
         |--------------------------------------------------------------------------------|
      1. |        5   2006      54923                            Abstrakt forlag        0 |
         |--------------------------------------------------------------------------------|
      2. |       11   2006      53503                                  Routledge        0 |
         |--------------------------------------------------------------------------------|
      3. |       26   2004      67831                             Fagbokforlaget        0 |
         |--------------------------------------------------------------------------------|
      4. |       26   2009      43696         Jurist- og Økonomforbundets Forlag        0 |
      5. |       26   2009      43695         Jurist- og Økonomforbundets Forlag        0 |
         |--------------------------------------------------------------------------------|
      6. |       31   2006      55447                             Fagbokforlaget        0 |
         |--------------------------------------------------------------------------------|
      7. |       31   2008     337381            Journal of Population Economics        1 |
         |--------------------------------------------------------------------------------|
      8. |       35   2006      33963                                   Daidalos        0 |
         |--------------------------------------------------------------------------------|
      9. |       65   2006      55447                             Fagbokforlaget        0 |
     10. |       65   2006      54473                             Fagbokforlaget        0 |
     11. |       65   2006      53503                                  Routledge        0 |
         |--------------------------------------------------------------------------------|
     12. |       66   2006      54032                             Fagbokforlaget        0 |
         |--------------------------------------------------------------------------------|
     13. |       78   2010     338899              Acta Neurologica Scandinavica        0 |
         |--------------------------------------------------------------------------------|
     14. |       90   2008     337433   Journal of Economic Dynamics and Control        0 |
         |--------------------------------------------------------------------------------|
     15. |       92   2008     336163   Journal of Economic Dynamics and Control        0 |
         |--------------------------------------------------------------------------------|
     16. |       92   2010     339254                              Health Policy        0 |
         |--------------------------------------------------------------------------------|
     17. |      109   2008     337381            Journal of Population Economics        1 |
         |--------------------------------------------------------------------------------|
     18. |      114   2005      59866                            Springer-Verlag        0 |
         |--------------------------------------------------------------------------------|
     19. |      114   2008     337433   Journal of Economic Dynamics and Control        0 |
     20. |      114   2008     337356                               Optimization        0 |
         +--------------------------------------------------------------------------------+
    See also https://www.stata.com/support/faqs/d...ble-recording/

    Spelling should be "Researcher".

    Comment


    • #3
      Try this:

      Code:
      . gen dummy = Channel=="Journal of Population Economics" & Year==2008
      
      . list, sep(0)
      
           +-------------------------------------------------------------------------------+
           | Resera~r   Year   Public~n                                    Channel   dummy |
           |-------------------------------------------------------------------------------|
        1. |       35   2006      33963                                   Daidalos       0 |
        2. |       26   2009      43695         Jurist- og Økonomforbundets Forlag       0 |
        3. |       26   2009      43696         Jurist- og Økonomforbundets Forlag       0 |
        4. |       11   2006      53503                                  Routledge       0 |
        5. |       65   2006      53503                                  Routledge       0 |
        6. |       66   2006      54032                             Fagbokforlaget       0 |
        7. |       65   2006      54473                             Fagbokforlaget       0 |
        8. |        5   2006      54923                            Abstrakt forlag       0 |
        9. |       65   2006      55447                             Fagbokforlaget       0 |
       10. |       31   2006      55447                             Fagbokforlaget       0 |
       11. |      114   2005      59866                            Springer-Verlag       0 |
       12. |       26   2004      67831                             Fagbokforlaget       0 |
       13. |       92   2008     336163   Journal of Economic Dynamics and Control       0 |
       14. |      114   2008     337356                               Optimization       0 |
       15. |      109   2008     337381            Journal of Population Economics       1 |
       16. |       31   2008     337381            Journal of Population Economics       1 |
       17. |      114   2008     337433   Journal of Economic Dynamics and Control       0 |
       18. |       90   2008     337433   Journal of Economic Dynamics and Control       0 |
       19. |       78   2010     338899              Acta Neurologica Scandinavica       0 |
       20. |       92   2010     339254                              Health Policy       0 |
           +-------------------------------------------------------------------------------+

      Comment


      • #4
        Thank you, Nick
        Thank you, Joro


        Comment


        • #5

          egen wanted = max(Channel == "Journal of Population Economics"), by(Rese Year)

          sort Rese Year

          list, sepby(Rese Year)

          +--------------------------------------------------------------------------------+
          | Resera~r Year Public~n Channel wanted |
          |--------------------------------------------------------------------------------|
          1. | 5 2006 54923 Abstrakt forlag 0 |
          |--------------------------------------------------------------------------------|
          2. | 11 2006 53503 Routledge 0 |
          |--------------------------------------------------------------------------------|
          3. | 26 2004 67831 Fagbokforlaget 0 |
          |--------------------------------------------------------------------------------|
          4. | 26 2009 43696 Jurist- og Økonomforbundets Forlag 0 |
          5. | 26 2009 43695 Jurist- og Økonomforbundets Forlag 0 |
          |--------------------------------------------------------------------------------|
          6. | 31 2006 55447 Fagbokforlaget 0 |
          |--------------------------------------------------------------------------------|
          7. | 31 2008 337381 Journal of Population Economics 1 |
          |--------------------------------------------------------------------------------|
          8. | 35 2006 33963 Daidalos 0 |
          |--------------------------------------------------------------------------------|
          9. | 65 2006 55447 Fagbokforlaget 0 |
          10. | 65 2006 54473 Fagbokforlaget 0 |
          11. | 65 2006 53503 Routledge 0 |
          |--------------------------------------------------------------------------------|
          12. | 66 2006 54032 Fagbokforlaget 0 |
          |--------------------------------------------------------------------------------|
          13. | 78 2010 338899 Acta Neurologica Scandinavica 0 |
          |--------------------------------------------------------------------------------|
          14. | 90 2008 337433 Journal of Economic Dynamics and Control 0 |
          |--------------------------------------------------------------------------------|
          15. | 92 2008 336163 Journal of Economic Dynamics and Control 0 |
          |--------------------------------------------------------------------------------|
          16. | 92 2010 339254 Health Policy 0 |
          |--------------------------------------------------------------------------------|
          17. | 109 2008 337381 Journal of Population Economics 1 |
          |--------------------------------------------------------------------------------|
          18. | 114 2005 59866 Springer-Verlag 0 |
          |--------------------------------------------------------------------------------|
          19. | 114 2008 337433 Journal of Economic Dynamics and Control 0 |
          20. | 114 2008 337356 Optimization 0 |
          +--------------------------------------------------------------------------------+
          [/CODE]

          See also https://www.stata.com/support/faqs/d...ble-recording/

          Spelling should be "Researcher".

          [/QUOTE]

          Hello again

          Do you see why the dummy is =1 for the channel "Labour Economics"?


          +----------------------------------------------------------------------------+
          | wanted Resear~r Channel Year |
          |----------------------------------------------------------------------------|
          1. | 0 35 Daidalos 2006 |
          2. | 0 26 Jurist- og Økonomforbundets Forlag 2009 |
          3. | 0 26 Jurist- og Økonomforbundets Forlag 2009 |
          4. | 0 11 Routledge 2006 |
          5. | 0 65 Routledge 2006 |
          |----------------------------------------------------------------------------|
          6. | 0 66 Fagbokforlaget 2006 |
          7. | 0 65 Fagbokforlaget 2006 |
          8. | 0 5 Abstrakt forlag 2006 |
          9. | 0 65 Fagbokforlaget 2006 |
          10. | 0 31 Fagbokforlaget 2006 |
          |----------------------------------------------------------------------------|
          11. | 0 114 Springer-Verlag 2005 |
          12. | 0 26 Fagbokforlaget 2004 |
          13. | 0 92 Journal of Economic Dynamics and Control 2008 |
          14. | 0 114 Optimization 2008 |
          15. | 1 109 Journal of Population Economics 2008 |
          |----------------------------------------------------------------------------|
          16. | 1 31 Journal of Population Economics 2008 |
          17. | 0 114 Journal of Economic Dynamics and Control 2008 |
          18. | 0 90 Journal of Economic Dynamics and Control 2008 |
          19. | 0 78 Acta Neurologica Scandinavica 2010 |
          20. | 0 92 Health Policy 2010 |
          |----------------------------------------------------------------------------|
          21. | 0 128 Empirical Economics 2010 |
          22. | 0 115 European Review of Agricultural Economics 2010 |
          23. | 0 92 Social Science and Medicine 2010 |
          24. | 0 50 Social Science and Medicine 2010 |
          25. | 0 121 Social Science and Medicine 2010 |
          |----------------------------------------------------------------------------|
          26. | 0 32 International Tax and Public Finance 2010 |
          27. | 0 32 International Tax and Public Finance 2010 |
          28. | 0 63 Labour Economics 2010 |
          29. | 0 29 Samfunnsøkonomen 2009 |
          30. | 0 67 The Scandinavian Journal of Economics 2010 |
          |----------------------------------------------------------------------------|
          31. | 0 65 The Scandinavian Journal of Economics 2010 |
          32. | 0 31 The Scandinavian Journal of Economics 2010 |
          33. | 0 114 Economic Theory 2010 |
          34. | 0 44 Economic Modelling 2010 |
          35. | 0 114 Journal of Risk 2009 |
          |----------------------------------------------------------------------------|
          36. | 0 103 Journal of International Economics 2009 |
          37. | 0 51 The Scandinavian Journal of Economics 2010 |
          38. | 0 114 Journal of dynamical and control systems 2009 |
          39. | 0 91 Southern Economic Journal 2009 |
          40. | 0 91 Labour Economics 2009 |
          |----------------------------------------------------------------------------|
          41. | 0 70 Journal of Health Economics 2010 |
          42. | 0 91 Journal of Health Economics 2010 |
          43. | 0 47 Science 2010 |
          44. | 0 28 Science 2010 |
          45. | 0 4 Science 2010 |
          |----------------------------------------------------------------------------|
          46. | 0 15 Science 2010 |
          47. | 0 67 European Economic Review 2010 |
          48. | 0 11 European Economic Review 2010 |
          49. | 0 65 European Economic Review 2010 |
          50. | 0 10 Empirical Economics 2010 |
          |----------------------------------------------------------------------------|
          51. | 0 9 Empirical Economics 2010 |
          52. | 0 35 Games and Economic Behavior 2010 |
          53. | 0 109 Games and Economic Behavior 2010 |
          54. | 0 54 Human Resources for Health 2010 |
          55. | 0 87 Health Economics 2010 |
          |----------------------------------------------------------------------------|
          56. | 0 28 European Economic Review 2010 |
          57. | 0 4 European Economic Review 2010 |
          58. | 0 15 European Economic Review 2010 |
          59. | 0 87 Social Science and Medicine 2010 |
          60. | 0 11 Social Science and Medicine 2010 |
          |----------------------------------------------------------------------------|
          61. | 0 90 The B.E. Journals in Economic Analysis & Policy 2010 |
          62. | 0 33 The B.E. Journals in Economic Analysis & Policy 2010 |
          63. | 0 130 Public Choice 2010 |
          64. | 0 31 Spine 2009 |
          65. | 0 114 Computational Economics 2009 |
          |----------------------------------------------------------------------------|
          66. | 0 29 Computational Economics 2009 |
          67. | 0 26 Journal of Policy Modeling 2009 |
          68. | 0 90 Samfunnsøkonomen 2009 |
          69. | 0 114 Annals of Operations Research 2009 |
          70. | 0 31 Health and Place 2009 |
          |----------------------------------------------------------------------------|
          71. | 0 84 Review of Development Economics 2009 |
          72. | 0 33 Journal of International Economics 2009 |
          73. | 0 66 Journal of International Economics 2009 |
          74. | 0 91 Journal of International Economics 2009 |
          75. | 0 26 Samfundsøkonomen 2009 |
          |----------------------------------------------------------------------------|
          76. | 0 13 European Economic Review 2009 |
          77. | 0 114 Environment and Development Economics 2009 |
          78. | 0 50 Clinical Respiratory Journal 2009 |
          79. | 0 87 Health Economics 2009 |
          80. | 0 87 Economics and Human Biology 2008 |
          |----------------------------------------------------------------------------|
          81. | 0 120 Applied Economics Quarterly 2008 |
          82. | 0 115 Applied Economics Quarterly 2008 |
          83. | 0 114 Optimization Letters 2008 |
          84. | 0 92 Samfunnsøkonomen 2008 |
          85. | 0 50 Samfunnsøkonomen 2008 |
          |----------------------------------------------------------------------------|
          86. | 0 121 Samfunnsøkonomen 2008 |
          87. | 0 57 Samfunnsøkonomen 2008 |
          88. | 0 57 The Scandinavian Journal of Economics 2008 |
          89. | 0 50 Respiratory Medicine 2008 |
          90. | 0 107 Labour Economics 2008 |
          |----------------------------------------------------------------------------|
          91. | 0 44 Journal of Development Studies 2008 |
          92. | 0 117 European Journal of Public Health 2008 |
          93. | 0 92 Tidsskrift for Den norske legeforening 2008 |
          94. | 0 99 Tidsskrift for Den norske legeforening 2008 |
          95. | 0 92 Tidsskrift for Den norske legeforening 2008 |
          |----------------------------------------------------------------------------|
          96. | 0 99 Tidsskrift for Den norske legeforening 2008 |
          97. | 1 65 Labour Economics 2008 |
          98. | 1 31 Labour Economics 2008 |
          99. | 1 65 Journal of Population Economics 2008 |
          +----------------------------------------------------------------------------+

          .


          Comment

          Working...
          X