Announcement

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

  • Re-scaling three variables to vary between 0 and 10

    Hi all. I have a dataset with subnational level information on deforestation in the Brazilian states from 1995 to 2014.

    In this dataset, I have three variables that measure the ideology of the state governor (gov_ideo_3), each state’s ideology score (ideo_sis_gov), and the president’s ideology score (pres_ideo).

    All the three variables are on the same scale (i.e., -1 to +1, where -1 is the most extreme position to the left and +1 the most extreme position to the right)

    What I need: to re-scale these three variables so that the minimum “possible” score is 0 and the maximum “possible” score is 10.

    Important: the minimum and the maximum observed values cannot be 0 and 10, because in all three variables it is not possible to observe minimum values of -1 and maximum values of +1.


    How can such re-scaling be done?


    Part of the dataset follows below.

    Variables:

    year
    ibge_uf_code - state's ID
    estados - state’s name
    gov_ideo_3 - state's governor's ideology score
    ideo_sis_gov - state's ideology score
    pres_ideo - president's ideology score


    Code:
    * Example generated by -dataex-. For more info, type help dataex
    clear
    input float(year ibge_uf_code) str11 estados float(gov_ideo_3 ideo_sis_gov pres_ideo)
    1995 11 "Rondonia" .009857008  -.15697736 -.19499357
    1996 11 "Rondonia" .009857008  -.15697736 -.19499357
    1997 11 "Rondonia" .009857008   -.1583098   .1815582
    1998 11 "Rondonia" .009857008   -.1583098   .1815582
    1999 11 "Rondonia"   .8102344     .449283   .1815582
    2000 11 "Rondonia"   .8102344     .449283   .1815582
    2001 11 "Rondonia"   .8102344    .4514761  .21085827
    2002 11 "Rondonia"   .8102344    .4514761  .21085827
    2003 11 "Rondonia"  .21085827   .14709651  -.7633842
    2004 11 "Rondonia"  .21085827   .14709651  -.7633842
    2005 11 "Rondonia"  -.3748846   .14960054  -.4932221
    2006 11 "Rondonia"  -.3748846   .14960054  -.4932221
    2007 11 "Rondonia"  -.3759329    -.393243  -.4932221
    2008 11 "Rondonia"  -.3759329    -.393243  -.4932221
    2009 11 "Rondonia"  -.3759329  -.27025908  -.4984943
    2010 11 "Rondonia"  -.3759329  -.27025908  -.4984943
    2011 11 "Rondonia"  .09833692  -.07127651  -.4984943
    2012 11 "Rondonia"  .09833692  -.07127651  -.4984943
    2013 11 "Rondonia"  .09833692  -.02035712  -.4955083
    2014 11 "Rondonia"  .09833692  -.02035712  -.4955083
    1995 12 "Acre"       .7714077    .1738965 -.19499357
    1996 12 "Acre"       .7714077    .1738965 -.19499357
    1997 12 "Acre"       .7714077    .2296254   .1815582
    1998 12 "Acre"       .7071267    .2296254   .1815582
    1999 12 "Acre"      -.8606493   -.2597894   .1815582
    2000 12 "Acre"      -.8606493   -.2597894   .1815582
    2001 12 "Acre"      -.8606493  -.20892295  .21085827
    2002 12 "Acre"      -.8606493  -.20892295  .21085827
    2003 12 "Acre"      -.7633842   -.4304154  -.7633842
    2004 12 "Acre"      -.7633842   -.4304154  -.7633842
    2005 12 "Acre"      -.7633842   -.2735666  -.4932221
    2006 12 "Acre"      -.7633842   -.2735666  -.4932221
    2007 12 "Acre"      -.4932221   -.3755832  -.4932221
    2008 12 "Acre"      -.4932221   -.3755832  -.4932221
    2009 12 "Acre"      -.4932221   -.3040016  -.4984943
    2010 12 "Acre"      -.4932221   -.3040016  -.4984943
    2011 12 "Acre"      -.4984943   -.1862587  -.4984943
    2012 12 "Acre"      -.4984943   -.1862587  -.4984943
    2013 12 "Acre"      -.4984943  -.12496634  -.4955083
    2014 12 "Acre"      -.4984943  -.12496634  -.4955083
    1995 13 "Amazonas"   .7714077    .6232523 -.19499357
    1996 13 "Amazonas"   .7714077    .6232523 -.19499357
    1997 13 "Amazonas"   .7714077    .6727602   .1815582
    1998 13 "Amazonas"   .7714077    .6727602   .1815582
    1999 13 "Amazonas"   .8102344    .7050645   .1815582
    2000 13 "Amazonas"   .8102344    .7050645   .1815582
    2001 13 "Amazonas"   .8102344    .5948176  .21085827
    2002 13 "Amazonas"   .8102344    .5948176  .21085827
    2003 13 "Amazonas"  -.3748846   -.3294316  -.7633842
    2004 13 "Amazonas"  -.3748846   -.3294316  -.7633842
    2005 13 "Amazonas"  -.3748846   -.3030704  -.4932221
    2006 13 "Amazonas"  -.3748846   -.3030704  -.4932221
    2007 13 "Amazonas"  .13947605    .3451917  -.4932221
    2008 13 "Amazonas"  .13947605    .3451917  -.4932221
    2009 13 "Amazonas"  .13947605    .3204229  -.4984943
    2010 13 "Amazonas"   .4200475    .3204229  -.4984943
    2011 13 "Amazonas"    .345577   .29489672  -.4984943
    2012 13 "Amazonas"    .345577   .29489672  -.4984943
    2013 13 "Amazonas"    .345577   .34328794  -.4955083
    2014 13 "Amazonas"    .345577   .34328794  -.4955083
    1995 14 "Roraima"    .5171585    .1208371 -.19499357
    1996 14 "Roraima"    .5171585    .1208371 -.19499357
    1997 14 "Roraima"    .5171585    .2771065   .1815582
    1998 14 "Roraima"    .5171585    .2771065   .1815582
    1999 14 "Roraima"    .8723611    .4856019   .1815582
    2000 14 "Roraima"    .8723611    .4856019   .1815582
    2001 14 "Roraima"    .8723611    .4816539  .21085827
    2002 14 "Roraima"     .619985    .4816539  .21085827
    2003 14 "Roraima"   -.7633842    .4713193  -.7633842
    2004 14 "Roraima"   -.7633842    .4713193  -.7633842
    2005 14 "Roraima"    .4854508    .4057178  -.4932221
    2006 14 "Roraima"   .21085827    .4057178  -.4932221
    2007 14 "Roraima"   .16870013   .13803422  -.4932221
    2008 14 "Roraima"   .16870013   .13803422  -.4932221
    2009 14 "Roraima"   .16870013   .09631015  -.4984943
    2010 14 "Roraima"   .16870013   .09631015  -.4984943
    2011 14 "Roraima"   .13112865    .3986013  -.4984943
    2012 14 "Roraima"   .13112865    .3986013  -.4984943
    2013 14 "Roraima"   .13112865    .5214249  -.4955083
    2014 14 "Roraima"   -.4516903    .5214249  -.4955083
    1995 15 "Para"     -.19499357   .11581126 -.19499357
    1996 15 "Para"     -.19499357   .11581126 -.19499357
    1997 15 "Para"     -.19499357    .2880512   .1815582
    1998 15 "Para"     -.19499357    .2880512   .1815582
    1999 15 "Para"       .1815582 -.007553405   .1815582
    2000 15 "Para"       .1815582 -.007553405   .1815582
    2001 15 "Para"       .1815582   .04864629  .21085827
    2002 15 "Para"       .1815582   .04864629  .21085827
    2003 15 "Para"      .21085827  -.24894403  -.7633842
    2004 15 "Para"      .21085827  -.24894403  -.7633842
    2005 15 "Para"      .21085827    -.170254  -.4932221
    2006 15 "Para"      .21085827    -.170254  -.4932221
    2007 15 "Para"      -.4932221  -.12342624  -.4932221
    2008 15 "Para"      -.4932221  -.12342624  -.4932221
    2009 15 "Para"      -.4932221    -.157531  -.4984943
    2010 15 "Para"      -.4932221    -.157531  -.4984943
    2011 15 "Para"      .13112865  -.14406846  -.4984943
    2012 15 "Para"      .13112865  -.14406846  -.4984943
    2013 15 "Para"      .13112865  -.07156263  -.4955083
    2014 15 "Para"      .13112865  -.07156263  -.4955083
    end


  • #2
    PEDAGOGICAL EDIT:

    Important: the minimum and the maximum observed values cannot be 0 and 10, because in all three variables it is not possible to observe minimum values of -1 and maximum values of +1.
    This is the definition of an open interval. Therefore parentheses and not square brackets are required below:

    For \((\)-\(1, ~1) \rightarrow (0, 10)\), I would suggest adding 1 and multiplying by 5.
    Last edited by Andrew Musau; 15 Nov 2022, 10:34.

    Comment


    • #3
      Thanks Andrew. Can you specify how I can do that with the "generate" command?

      Comment


      • #4
        Code:
        foreach var in gov_ideo_3 ideo_sis_gov pres_ideo{
            g `var'_r= 5*(`var'+1)
        }
        sum *_r

        Comment


        • #5
          Awesome! Thanks a lot Andrew.

          Comment

          Working...
          X