Announcement

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

  • Generating a new variable with conditions

    Hi guys!

    I have a dataset from year 1700 to 1900 on british gdp and population. The variables are:

    1) anno (year)
    2) PIL_nom_GBUK, which is the nominal GDP of Great Britain from 1700 to 1800, and then it is the nominal GDP of UK (GB + Northern Ireland) from 1801
    3) Pop_GB, the population of Great Britain
    4) Pop_UK, the population of UK

    Here there is a sample:
    Code:
    * Example generated by -dataex-. For more info, type help dataex
    clear
    input int anno double(PIL_nom_GBUK Pop_GB Pop_UK)
    1700  79.36639342216591  6.205051294339165  6.575830854946653
    1701  82.29255065539935  6.243315983045056  6.613147071943983
    1702  80.02515499754767  6.287647280902274  6.656532324328272
    1703  74.21149638516411  6.341897161069989  6.709838579052267
    1704  89.95262413015233 6.3727119315090235 6.7397121378862375
    1705  83.77125936954829 6.3874823453321286  6.753543747768224
    1706  68.91059342522354  6.408450380075861  6.773575380075862
    1707   76.2850050639657  6.431911676255449  6.804473899561297
    1708  83.89986573556004  6.454156264800768  6.834307200054715
    1709   79.3191978029728   6.46899236922152  6.856886590734722
    1710  74.37130198898305   6.48755856217637   6.88335379278082
    1711  75.26647315998585  6.480122438085237 6.8839796132659155
    1712  73.41236686798504 6.4677257513639725  6.879809084697307
    1713  72.15256060662823  6.478882275834852  6.894065365544102
    1714   80.3223420201773  6.502455019493225  6.920761182438872
    1715  74.85401956430758 6.5099169287339596 6.9313696571696175
    1716   77.9944601076646  6.549664320037117  6.974287282928869
    1717  83.51729873278094   6.59441305443385  7.022230098789508
    1718   87.8013220369702  6.639199523461984  7.070234675670342
    1719  84.62148985633199  6.684023837556813  7.118301304736986
    1720  93.14592301532916  6.661746445637375  7.099290616998276
    1721  85.73055569187113 6.6543807338731265 7.0952161820831785
    1722  84.84705947224151  6.660699764024171  7.104851246591317
    1723  84.69700394160797  6.685698617223378 7.1331910778854715
    1724  83.83908571450534  6.709474953096012  7.160333523221674
    1725  87.69293439669414  6.734518875177854 7.1887688751778525
    1726  86.91165874062534  6.791987814756587  7.245550175993482
    1727  85.17542327773116 6.8320509414618025  7.284926704875754
    1728  92.79616464227023  6.766135656315756   7.21832586127116
    1729  85.76078856880203  6.657749947140612   7.10925563142849
    1730    82.102595262551   6.57674249931289  7.027564699153263
    1731  80.03975011496811 6.5718443781073725  7.021984128151647
    1732   82.4085062686965 6.6006735094638564  7.050131842797189
    1733  84.93930459797306  6.635777065019221  7.080587597209955
    1734  84.92198523243191  6.704666308339079 7.1448771018078165
    1735  84.50883477366416  6.764858848182817  7.200517468341752
    1736  90.16768687829689  6.818846741600026  7.250000261992445
    1737  84.11351561601026  6.860364350168041  7.287059357554696
    1738   84.4301343444955  6.891901153865994  7.314183753258864
    1739  84.40543014415867  6.935993177801534   7.35390899744554
    1740  89.64518311978443  6.973858085527374  7.387452281830577
    1741  93.42227234782419  6.990444455683417  7.399761718096232
    1742  93.34414010457972  6.918001532023721 7.3230860878676785
    1743  90.06296168469508  6.915765560855875  7.316661180102443
    1744  88.14831503025016  6.963738415922356  7.360488415922356
    1745  87.17395323198978  7.035611465545335  7.434071658268542
    1746  92.38150169010427 7.0786536140777425  7.478831371317858
    1747  95.15283472049227  7.110423788196756  7.512326513523631
    1748  95.95374996241853  7.127136702539388  7.530771831435996
    1749  96.38940285439226   7.17279436232214   7.57816936232214
    1750  97.41809719137692  7.221009194177958  7.638744771655171
    1751  95.78900648019506 7.2654906563793675  7.695963706494006
    1752 103.17309766099176  7.310738010081235  7.754336920171932
    1753 102.28791792928527   7.36348791645838  7.820612916458381
    1754  98.61896979085097  7.414931318126537  7.879538442514208
    1755  99.79259099718638  7.465070379797069  7.937282094386689
    1756  102.8036419343457 7.5239509078558795  8.003891682956027
    1757 116.09836492814382  7.555170073713647   8.04296641693633
    1758 116.77394796206488 7.5738209246855215   8.06960141429233
    1759 110.72662589906685  7.599979095918081  8.103874414712132
    1760 114.57490387600458  7.644908652560328  8.157051622332958
    1761  116.6280767319507  7.697310720676118  8.217836337217378
    1762 115.64485661726508  7.725884826957718  8.254930295639927
    1763 121.50442269664609  7.708151342226782  8.245856114170492
    1764 122.65638039959005 7.7454539145692385  8.291959723401165
    1765  122.9525172545312  7.805217422149737  8.360668321362336
    1766 125.88834004754648  7.839945660361114  8.404488061283647
    1767 130.71096909091156  7.858415592980735  8.432198303371832
    1768 127.54460908078637   7.87812025076021  8.461294514032117
    1769 129.64574032171123  7.928987911004733  8.521707446089577
    1770 127.01665213014971 7.9835491640198075  8.585970205888371
    1771 135.23614377119685  8.033077737594171  8.645359078437872
    1772  136.0058086351932   8.09252372187677  8.714826752963715
    1773 138.51086929136744   8.15440481692786  8.786893571143965
    1774 137.85297101383622   8.21249777080606  8.855338965892491
    1775 143.18445104015245  8.297891327731257  8.951254410229568
    1776 145.01220067028925  8.375749157623915  9.039806347540468
    1777 153.22618758516214  8.456019325605928  9.130945661807376
    1778 152.40924772766363  8.543664190187622  9.229637576539412
    1779  147.4180573230345  8.622542082880464   9.31974333514052
    1780 153.51658384632782  8.667861977530935  9.376474871010895
    1781  177.1660592016561  8.762727170226604   9.48293848823317
    1782 176.17498984816606  8.829017771336586  9.561017354405738
    1783  171.8349441815293  8.845714094320543  9.589694890257611
    1784 165.85922184328768  8.929211515467232  9.685369630206027
    1785 165.23643976513299  9.012614625508798  9.781149374803178
    1786 177.71771923972136  9.108280809323965  9.889394771285492
    1787 173.77072487012975    9.2149523959016 10.008851464397099
    1788 167.71402207462967  9.309160325849406 10.116053764772554
    1789 168.90436541979776  9.432863078093044 10.252963576524241
    1790 186.30662514560473   9.54039941755421 10.373923145823316
    1791 188.00630985425622  9.660132298143195 10.507298964809863
    1792  207.0034945832193  9.771111046042206 10.632241134948758
    1793  201.5472241252912  9.873352281442246 10.748675944657128
    1794 196.96278952105942  9.960724683079192  10.85047586615168
    1795 240.11070743198758 10.073806800565047 10.978223305051278
    1796  251.4925319428565 10.174481845746017 11.093805392765633
    1797 252.10535329436289 10.308183435586795 11.242659730427112
    1798 265.79027267760404 10.427015608092965 11.376894405878023
    1799  294.1826755823731 10.549393198921283 11.514928371363265
    1800 335.81510194897817 10.614056386571129 11.595505989822005
    1801 369.36233795405013             10.686 11.683626343621555
    1802  319.8058313698263             10.774 11.788069717070647
    1803  315.4398529976345             10.898 11.928784118377125
    1804 335.58582314537097             11.049 12.096774014756903
    1805  366.6219227812475             11.215 12.280043947056763
    1806  371.5414304954829             11.378 12.460598530967985
    1807  397.3742546313211             11.536 12.636442458259962
    1808 387.97623335844423             11.686 12.804580498034168
    1809  424.2574515911648             11.839  12.97601749799878
    1810  467.5665129325724             11.989 13.144758385764307
    1811  447.2090197381457             12.146 13.320808170160591
    1812  454.8631919634387             12.331 13.525171942575486
    1813  489.3989795301258             12.528 13.741854878315648
    end

    I would like to generate a new variable that represents per capita gdp of GB from 1700 to 1800 and per capita gdp of UK from 1801.
    In other terms, I want a new variable which is equal to PIL_nom_GBUK / Pop_GB from 1700 to 1800, and PIL_nom_GBUK / Pop_UK.

    Can someone help me?




  • #2
    Code:
    generate wanted = cond(anno<=1800,  PIL_nom_GBUK / Pop_GB, PIL_nom_GBUK / Pop_UK)
    or, less tersely
    Code:
    generate wanted =  PIL_nom_GBUK / Pop_UK
    replace wanted = PIL_nom_GBUK / Pop_GB if anno<=1800

    Comment


    • #3
      William Lisowski Thank you very much!

      Comment

      Working...
      X