Announcement

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

  • replacing values using the loops commands in stata

    Hi Everyone,

    I am trying to replace missings in the GHI varibale by using this command
    Code:
    replace GHI=5.9169803 if city=="adelanto" & year ==2007|year==2008
    However, it is cumbersome if not looping. Would anyone help with this by suggesting a loop command for this case?

    Code:
    * Example generated by -dataex-. To install: ssc install dataex
    clear
    input float year str21 city float GHI
    2007 "adelanto"              .
    2008 "adelanto"              .
    2009 "adelanto"        5.91698
    2010 "adelanto"        5.91698
    2011 "adelanto"        5.91698
    2012 "adelanto"        5.91698
    2013 "adelanto"        5.91698
    2014 "adelanto"        5.91698
    2015 "adelanto"        5.91698
    2016 "adelanto"        5.91698
    2017 "adelanto"        5.91698
    2007 "agourahills"           .
    2008 "agourahills"     5.91698
    2009 "agourahills"     5.35798
    2010 "agourahills"     5.35798
    2011 "agourahills"     5.35798
    2012 "agourahills"     5.35798
    2013 "agourahills"     5.35798
    2014 "agourahills"     5.35798
    2015 "agourahills"     5.35798
    2016 "agourahills"     5.35798
    2017 "agourahills"     5.35798
    2005 "alameda"               .
    2006 "alameda"               .
    2007 "alameda"               .
    2008 "alameda"         5.91698
    2009 "alameda"        4.842005
    2010 "alameda"        4.842005
    2011 "alameda"        4.842005
    2012 "alameda"        4.842005
    2013 "alameda"        4.842005
    2014 "alameda"        4.842005
    2015 "alameda"        4.842005
    2016 "alameda"        4.842005
    2017 "alameda"        4.842005
    2009 "albany"         4.850235
    2010 "albany"         4.850235
    2011 "albany"         4.850235
    2012 "albany"         4.850235
    2013 "albany"         4.850235
    2014 "albany"         4.850235
    2015 "albany"         4.850235
    2016 "albany"         4.850235
    2017 "albany"         4.850235
    2005 "alhambra"              .
    2006 "alhambra"              .
    2007 "alhambra"              .
    2008 "alhambra"        5.91698
    2009 "alhambra"       5.269322
    2010 "alhambra"       5.269322
    2011 "alhambra"       5.269322
    2012 "alhambra"       5.269322
    2013 "alhambra"       5.269322
    2014 "alhambra"       5.269322
    2015 "alhambra"       5.269322
    2016 "alhambra"       5.269322
    2017 "alhambra"       5.269322
    2007 "alisoviejo"            .
    2008 "alisoviejo"      5.91698
    2009 "alisoviejo"     5.190601
    2010 "alisoviejo"     5.190601
    2011 "alisoviejo"     5.190601
    2012 "alisoviejo"     5.190601
    2013 "alisoviejo"     5.190601
    2014 "alisoviejo"     5.190601
    2015 "alisoviejo"     5.190601
    2016 "alisoviejo"     5.190601
    2017 "alisoviejo"     5.190601
    2009 "alturas"        4.817854
    2010 "alturas"        4.817854
    2011 "alturas"        4.817854
    2012 "alturas"        4.817854
    2013 "alturas"        4.817854
    2014 "alturas"        4.817854
    2015 "alturas"        4.817854
    2016 "alturas"        4.817854
    2017 "alturas"        4.817854
    2009 "amador"         5.082078
    2010 "amador"         5.082078
    2011 "amador"         5.082078
    2012 "amador"         5.082078
    2013 "amador"         5.082078
    2014 "amador"         5.082078
    2015 "amador"         5.082078
    2016 "amador"         5.082078
    2017 "amador"         5.082078
    2009 "americancanyon" 4.956796
    2010 "americancanyon" 4.956796
    2011 "americancanyon" 4.956796
    2012 "americancanyon" 4.956796
    2013 "americancanyon" 4.956796
    2014 "americancanyon" 4.956796
    2015 "americancanyon" 4.956796
    2016 "americancanyon" 4.956796
    2017 "americancanyon" 4.956796
    2005 "anaheim"               .
    2006 "anaheim"               .
    2007 "anaheim"               .
    2008 "anaheim"         5.91698
    2009 "anaheim"        5.243647
    end
    I appreciate
    Ali

  • #2
    FAQ https://www.stata.com/support/faqs/d...issing-values/

    Please note the long-standing advice to scan the FAQs at https://www.statalist.org/forums/help#before

    Comment


    • #3
      Thank you Nick.

      Comment

      Working...
      X