Announcement

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

  • Fill in the blank with the previous row of values

    Code:
    * Example generated by -dataex-. To install: ssc install dataex
    clear
    input str3(actor1countrycode actor2countrycode) int year long quadclasscounta float goldsteinscalesum
    "ZWE" ""    2001  3861  -21172.7
    ""    ""    2002  6504  -33110.6
    ""    ""    2003  4757  -23477.1
    ""    ""    2004  3474  -16971.4
    ""    ""    2005  2984  -14214.1
    ""    ""    2006  3418  -16894.3
    ""    ""    2007  4003  -21136.3
    ""    ""    2008  9921  -50442.3
    ""    ""    2009 11578  -59898.3
    ""    ""    2010  8387  -43832.1
    ""    ""    2011 13325    -68969
    ""    ""    2012  9332  -48122.4
    ""    ""    2013 10750  -54493.6
    ""    ""    2014 14845  -77145.7
    ""    ""    2015 23599 -123382.7
    ""    ""    2016 28770 -150780.9
    ""    ""    2017 24270 -127356.4
    ""    ""    2018 23240 -120315.4
    ""    ""    2019 18637 -100998.4
    ""    ""    2020 15076  -80314.5
    ""    "AFG" 2007     2       -10
    ""    ""    2008    23    -142.8
    ""    ""    2009    25    -178.8
    ""    ""    2010    17      -133
    ""    ""    2011    31      -233
    ""    ""    2012     6       -55
    ""    ""    2013     1       -10
    ""    ""    2014     5     -37.8
    ""    ""    2015     4       -30
    ""    ""    2016    33      -282
    ""    ""    2017     9     -73.4
    ""    ""    2018    10       -82
    ""    ""    2019     3       -30
    ""    "AFR" 2001   186   -1031.5
    ""    "AGO" 2001    44    -366.5
    ""    ""    2020    19      -100
    ""    "ALB" 2013     1        -5
    ""    ""    2016     7       -43
    "ABW"    ""    2020     3       -15
    ""    "ARE" 2005     1       -10
    ""    ""    2007     4       -20
    ""    ""    2008     1        -7
    ""    ""    2009     1        -5
    ""    ""    2010     2        -4
    ""    ""    2011     9     -37.7
    ""    ""    2012     4       -17
    ""    ""    2013     4       -20
    ""    ""    2014    12       -69
    ""    ""    2015     4       -20
    ""    ""    2016    15       -89
    ""    ""    2017    20     -90.5
    ""    ""    2018    22       -93
    ""    ""    2019    42      -286
    ""    ""    2020    42      -176
    ""    "ARG" 2001     1        -2
    ""    ""    2009    18      -101
    ""    ""    2010     2        -4
    ""    ""    2014     1        -5
    ""    ""    2015     4       -40
    ""    ""    2016     1      -4.4
    ""    ""    2020     2      -8.8
    ""    "ARM" 2013     2       -10
    ""    ""    2015     2        -4
    ""    ""    2017     1        -5
    ""    "AUS" 2001    24    -121.1
    ""    ""    2002    48    -200.8
    ""    ""    2003    53    -309.3
    ""    ""    2004    16       -94
    ""    ""    2005     8     -29.2
    ""    ""    2018    12     -71.8
    ""    ""    2019    17      -123
    ""    ""    2020    25    -161.2
    ""    "ITA" 2001     2       -10
    ""    ""    2002     8       -47
    ""    ""    2003     8     -38.2
    ""    ""    2004     2       -10
    ""    ""    2005     4     -23.5
    ""    ""    2006     7     -48.5
    ""    ""    2007     1        -5
    ""    ""    2008    11       -60
    ""    ""    2009     7       -52
    ""    ""    2010     5       -35
    ""    ""    2011    55      -239
    ""    ""    2012     8     -47.6
    ""    ""    2013    11     -47.5
    ""    ""    2014     8     -39.5
    ""    ""    2015    17     -88.8
    ""    ""    2016    78      -728
    ""    ""    2017    11     -80.5
    ""    ""    2018     6       -53
    ""    ""    2019    22     -86.9
    ""    ""    2020     9       -63
    ""    "JAM" 2004     4       -36
    ""    ""    2008     1        -9
    ""    ""    2009     3       -14
    ""    ""    2010     2       -10
    ""    ""    2011     6       -20
    ""    ""    2012     1        -5
    ""    ""    2014     1        -5
    ""    ""    2015     2       -14
    end
    Hello,
    I want to fill the blanks in my dataset with the previous row in columns actor1countrycode and actor2countrycode, but the form of these two columns are different. And the synnax "replace" doesn't work, is anyone have a better idea. Thanks in advance.

  • #2
    This is an FAQ

    https://www.stata.com/support/faqs/d...issing-values/

    but

    the syntax "replace" doesn't work
    doesn't explain your problem unless you show the exact syntax you used and explain what doesn't work means in your case. I once compiled a list of about 20 meanings for doesn't work, among which "I got an error message" and "the results are not what I expect" were prominent (but quite different cases).

    The FAQ Advice even flags this as something not to say

    Never say just that something "doesn't work" or "didn't work", but explain precisely in what sense you didn't get what you wanted.

    Comment

    Working...
    X