Announcement

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

  • Help with reshaping data. Stata says' variable contains missing values in unbalanced dataset' .

    I am using reshape wide var, i(country year) j(id) to reshape this dataset. However, I keep getting the error that variable id contains missing values. This is an unbalanced panel dataset. I don't see any missing data. I am not sure what I am doing wrong. Pls help. Thank you.



    input str52 country int year str80 id double var str80 series str3 CountryCode




    "Afghanistan" 2006 "budgetqual" 3 "CPIA quality of budgetary and financial management rating (1=low to 6=high)" "AFG"
    "Afghanistan" 2007 "budgetqual" 3 "CPIA quality of budgetary and financial management rating (1=low to 6=high)" "AFG"
    "Afghanistan" 2008 "budgetqual" 3 "CPIA quality of budgetary and financial management rating (1=low to 6=high)" "AFG"
    "Afghanistan" 2009 "budgetqual" 3.5 "CPIA quality of budgetary and financial management rating (1=low to 6=high)" "AFG"
    "Afghanistan" 2010 "budgetqual" 3.5 "CPIA quality of budgetary and financial management rating (1=low to 6=high)" "AFG"
    "Afghanistan" 2011 "budgetqual" 3.5 "CPIA quality of budgetary and financial management rating (1=low to 6=high)" "AFG"
    "Afghanistan" 2012 "budgetqual" 3.5 "CPIA quality of budgetary and financial management rating (1=low to 6=high)" "AFG"
    "Afghanistan" 2013 "budgetqual" 3.5 "CPIA quality of budgetary and financial management rating (1=low to 6=high)" "AFG"
    "Afghanistan" 2014 "budgetqual" 3.5 "CPIA quality of budgetary and financial management rating (1=low to 6=high)" "AFG"
    "Afghanistan" 2015 "budgetqual" 3.5 "CPIA quality of budgetary and financial management rating (1=low to 6=high)" "AFG"
    "Afghanistan" 2016 "budgetqual" 3.5 "CPIA quality of budgetary and financial management rating (1=low to 6=high)" "AFG"
    "Afghanistan" 2017 "budgetqual" 3.5 "CPIA quality of budgetary and financial management rating (1=low to 6=high)" "AFG"
    "Afghanistan" 2018 "budgetqual" 3.5 "CPIA quality of budgetary and financial management rating (1=low to 6=high)" "AFG"
    "Afghanistan" 2019 "budgetqual" 3.5 "CPIA quality of budgetary and financial management rating (1=low to 6=high)" "AFG"
    "Afghanistan" 2020 "budgetqual" 3.5 "CPIA quality of budgetary and financial management rating (1=low to 6=high)" "AFG"
    "Afghanistan" 2022 "budgetqual" 2 "CPIA quality of budgetary and financial management rating (1=low to 6=high)" "AFG"
    "Afghanistan" 2008 "cab" -2.357990467967306 "Current account balance (% of GDP)" "AFG"
    "Afghanistan" 2009 "cab" 2.236019434449175 "Current account balance (% of GDP)" "AFG"
    "Afghanistan" 2010 "cab" -3.643313896004812 "Current account balance (% of GDP)" "AFG"
    "Afghanistan" 2011 "cab" -12.61953809461889 "Current account balance (% of GDP)" "AFG"
    "Afghanistan" 2012 "cab" -25.87068133062452 "Current account balance (% of GDP)" "AFG"
    "Afghanistan" 2013 "cab" -25.29005841519043 "Current account balance (% of GDP)" "AFG"
    "Afghanistan" 2014 "cab" -15.77241979308084 "Current account balance (% of GDP)" "AFG"
    "Afghanistan" 2015 "cab" -21.91265722122699 "Current account balance (% of GDP)" "AFG"
    "Afghanistan" 2016 "cab" -14.95019518857257 "Current account balance (% of GDP)" "AFG"
    "Afghanistan" 2017 "cab" -18.95596121837634 "Current account balance (% of GDP)" "AFG"
    "Afghanistan" 2018 "cab" -21.58527405970144 "Current account balance (% of GDP)" "AFG"
    "Afghanistan" 2019 "cab" -20.17046446912646 "Current account balance (% of GDP)" "AFG"
    "Afghanistan" 2020 "cab" -15.71830278432258 "Current account balance (% of GDP)" "AFG"
    "Afghanistan" 2003 "gdpgro" 8.832277812635695 "GDP growth (annual %)" "AFG"
    "Afghanistan" 2004 "gdpgro" 1.414117980589765 "GDP growth (annual %)" "AFG"
    "Afghanistan" 2005 "gdpgro" 11.22971482364288 "GDP growth (annual %)" "AFG"
    "Afghanistan" 2006 "gdpgro" 5.357403251263634 "GDP growth (annual %)" "AFG"
    "Afghanistan" 2007 "gdpgro" 13.82631954797624 "GDP growth (annual %)" "AFG"
    "Afghanistan" 2008 "gdpgro" 3.924983821615768 "GDP growth (annual %)" "AFG"
    "Afghanistan" 2009 "gdpgro" 21.39052839310669 "GDP growth (annual %)" "AFG"
    "Afghanistan" 2010 "gdpgro" 14.36244146926822 "GDP growth (annual %)" "AFG"
    "Afghanistan" 2011 "gdpgro" .4263547845293516 "GDP growth (annual %)" "AFG"
    "Afghanistan" 2012 "gdpgro" 12.75228708871651 "GDP growth (annual %)" "AFG"
    "Afghanistan" 2013 "gdpgro" 5.600744658081737 "GDP growth (annual %)" "AFG"
    "Afghanistan" 2014 "gdpgro" 2.724543363948868 "GDP growth (annual %)" "AFG"
    "Afghanistan" 2015 "gdpgro" 1.451314660097623 "GDP growth (annual %)" "AFG"
    "Afghanistan" 2016 "gdpgro" 2.260314201304567 "GDP growth (annual %)" "AFG"
    "Afghanistan" 2017 "gdpgro" 2.647003201957403 "GDP growth (annual %)" "AFG"
    "Afghanistan" 2018 "gdpgro" 1.189228128380364 "GDP growth (annual %)" "AFG"
    "Afghanistan" 2019 "gdpgro" 3.911603419422917 "GDP growth (annual %)" "AFG"
    "Afghanistan" 2020 "gdpgro" -2.351100673446098 "GDP growth (annual %)" "AFG"
    "Afghanistan" 2021 "gdpgro" -20.73883936763433 "GDP growth (annual %)" "AFG"
    "Afghanistan" 2002 "gdplocal" 487122374995.561 "GDP (constant LCU)" "AFG"
    "Afghanistan" 2003 "gdplocal" 530146376442.678 "GDP (constant LCU)" "AFG"
    "Afghanistan" 2004 "gdplocal" 537643271675.399 "GDP (constant LCU)" "AFG"
    "Afghanistan" 2005 "gdplocal" 598019077853.0499 "GDP (constant LCU)" "AFG"
    "Afghanistan" 2006 "gdplocal" 630057371373.1261 "GDP (constant LCU)" "AFG"
    "Afghanistan" 2007 "gdplocal" 717171116874.7539 "GDP (constant LCU)" "AFG"
    "Afghanistan" 2008 "gdplocal" 745319967185.389 "GDP (constant LCU)" "AFG"
    "Afghanistan" 2009 "gdplocal" 904747846385.6731 "GDP (constant LCU)" "AFG"
    "Afghanistan" 2010 "gdplocal" 1034691726267.28 "GDP (constant LCU)" "AFG"
    "Afghanistan" 2011 "gdplocal" 1039103183947.35 "GDP (constant LCU)" "AFG"
    "Afghanistan" 2012 "gdplocal" 1171612605112.31 "GDP (constant LCU)" "AFG"
    "Afghanistan" 2013 "gdplocal" 1237231635506.55 "GDP (constant LCU)" "AFG"
    "Afghanistan" 2014 "gdplocal" 1270940547928.42 "GDP (constant LCU)" "AFG"
    "Afghanistan" 2015 "gdplocal" 1289385894421.63 "GDP (constant LCU)" "AFG"
    "Afghanistan" 2016 "gdplocal" 1318530066902.86 "GDP (constant LCU)" "AFG"
    "Afghanistan" 2017 "gdplocal" 1353431599992.55 "GDP (constant LCU)" "AFG"
    "Afghanistan" 2018 "gdplocal" 1369526989278.05 "GDP (constant LCU)" "AFG"
    "Afghanistan" 2019 "gdplocal" 1423097453820.57 "GDP (constant LCU)" "AFG"
    "Afghanistan" 2020 "gdplocal" 1.389639e+12 "GDP (constant LCU)" "AFG"
    "Afghanistan" 2021 "gdplocal" 1.101444e+12 "GDP (constant LCU)" "AFG"
    "Afghanistan" 2002 "gdpusd" 3825701405.51958 "GDP (current US$)" "AFG"
    "Afghanistan" 2003 "gdpusd" 4520946849.320794 "GDP (current US$)" "AFG"
    "Afghanistan" 2004 "gdpusd" 5224896718.67782 "GDP (current US$)" "AFG"
    "Afghanistan" 2005 "gdpusd" 6203256497.090445 "GDP (current US$)" "AFG"
    "Afghanistan" 2006 "gdpusd" 6971758332.889174 "GDP (current US$)" "AFG"
    "Afghanistan" 2007 "gdpusd" 9747886104.532513 "GDP (current US$)" "AFG"
    "Afghanistan" 2008 "gdpusd" 10109296957.65692 "GDP (current US$)" "AFG"
    "Afghanistan" 2009 "gdpusd" 12416152648.05725 "GDP (current US$)" "AFG"
    "Afghanistan" 2010 "gdpusd" 15856668496.38805 "GDP (current US$)" "AFG"
    "Afghanistan" 2011 "gdpusd" 17805098367.29525 "GDP (current US$)" "AFG"
    "Afghanistan" 2012 "gdpusd" 19907329905.97765 "GDP (current US$)" "AFG"
    "Afghanistan" 2013 "gdpusd" 20146416876.38864 "GDP (current US$)" "AFG"
    "Afghanistan" 2014 "gdpusd" 20497128600.33633 "GDP (current US$)" "AFG"
    "Afghanistan" 2015 "gdpusd" 19134221744.52937 "GDP (current US$)" "AFG"
    "Afghanistan" 2016 "gdpusd" 18116572399.1298 "GDP (current US$)" "AFG"
    "Afghanistan" 2017 "gdpusd" 18753456506.57082 "GDP (current US$)" "AFG"
    "Afghanistan" 2018 "gdpusd" 18053222734.88808 "GDP (current US$)" "AFG"
    "Afghanistan" 2019 "gdpusd" 18799444414.5998 "GDP (current US$)" "AFG"
    "Afghanistan" 2020 "gdpusd" 19955929060.841 "GDP (current US$)" "AFG"
    "Afghanistan" 2021 "gdpusd" 14266499429.87457 "GDP (current US$)" "AFG"
    "Afghanistan" 2000 "goveffect" -2.17394614219666 "Government Effectiveness: Estimate" "AFG"
    "Afghanistan" 2002 "goveffect" -1.58768701553345 "Government Effectiveness: Estimate" "AFG"
    "Afghanistan" 2003 "goveffect" -1.17576801776886 "Government Effectiveness: Estimate" "AFG"
    "Afghanistan" 2004 "goveffect" -.945146262645721 "Government Effectiveness: Estimate" "AFG"
    "Afghanistan" 2005 "goveffect" -1.2288156747818 "Government Effectiveness: Estimate" "AFG"
    "Afghanistan" 2006 "goveffect" -1.47365152835846 "Government Effectiveness: Estimate" "AFG"
    "Afghanistan" 2007 "goveffect" -1.44011056423187 "Government Effectiveness: Estimate" "AFG"
    "Afghanistan" 2008 "goveffect" -1.52779507637024 "Government Effectiveness: Estimate" "AFG"
    "Afghanistan" 2009 "goveffect" -1.50775218009949 "Government Effectiveness: Estimate" "AFG"
    "Afghanistan" 2010 "goveffect" -1.47831559181213 "Government Effectiveness: Estimate" "AFG"
    "Afghanistan" 2011 "goveffect" -1.47410047054291 "Government Effectiveness: Estimate" "AFG"
    "Afghanistan" 2012 "goveffect" -1.37553513050079 "Government Effectiveness: Estimate" "AFG"
    end
    [/CODE]

  • #2
    Well, in your example data, id does not contain missing values. But I have never known Stata to be wrong in this situation. They are there, somewhere. You just haven't seen them. Run
    Code:
    browse if missing(id)
    and you will find them. Then you will need to figure out what to do about them. If they represent data errors, you should fill in the correct values. If they are not data errors, then you will need to delete those observations before you can -reshape- the data set to wide layout.

    If what you get from -browse if missing(id)- looks, at first glance, like there is nothing there, look again: you will see observation numbers at the left edge of the browser. This means that you have a bunch of empty observations (i.e. they have missing values for every variable) cluttering up your data set. This is not uncommon with data that has been imported from spreadsheets. In any case, just verify that, again, these don't represent errors in the creation of your data set. And once that is verified, you can just -drop- all of them.

    Comment


    • #3
      Furthermore, as an aside, it would help if you specified exactly what your code is. For instance, if I take your data extract and run your code

      Code:
      reshape wide var, i(country year) j(id)
      the first error I encounter is that Stata needs you to explicitly provide the option string when the j() variable is a string variable -- as is the case with your id. This tells me that your actual code is probably something else, and makes it harder to replicate your problem.

      Comment


      • #4
        Not really needed given excellent advice already, but I have often seen gunk at the bottom of a worksheet in MS Excel misread as missing values in Stata, all arising because of some extra stuff in a worksheet, and/or a careless mouse action, and/or insufficient checking of what was imported.

        Comment


        • #5
          Thank you . I tried to reshape this data to a wide format but failed so far. I need some help, please.


          . dataex

          ----------------------- copy starting from the next line -----------------------
          Code:
          * Example generated by -dataex-. For more info, type help dataex
          clear
          input str14(country id) int year float var str80 series str3 countrycode
          "Australia" "cab"            1999  -5.593632 "Current account balance (% of GDP)"           "AUS"
          "Australia" "inflation"      1999  1.4831294 "Inflation, consumer prices (annual %)"        "AUS"
          "Australia" "gdpgro"         1999   5.027647 "GDP growth (annual %)"                        "AUS"
          "Australia" "totresnogold"   1999   2.12e+10 "Total reserves minus gold (current US$)"      "AUS"
          "Australia" "totreswithgold" 1999   2.20e+10 "Total reserves (includes gold, current US$)"  "AUS"
          "Australia" "gdpusd"         1999   3.90e+11 "GDP (current US$)"                            "AUS"
          "Australia" "gdplocal"       1999   1.24e+12 "GDP (constant LCU)"                           "AUS"
          "Australia" "cab"            2000  -3.721401 "Current account balance (% of GDP)"           "AUS"
          "Australia" "regqual"        2000  1.5756135 "Regulatory Quality: Estimate"                 "AUS"
          "Australia" "goveffect"      2000  1.7321702 "Government Effectiveness: Estimate"           "AUS"
          "Australia" "gdpgro"         2000   3.921518 "GDP growth (annual %)"                        "AUS"
          "Australia" "inflation"      2000   4.457435 "Inflation, consumer prices (annual %)"        "AUS"
          "Australia" "terms"          2000  67.477974 "Net barter terms of trade index (2015 = 100)" "AUS"
          "Australia" "totresnogold"   2000   1.81e+10 "Total reserves minus gold (current US$)"      "AUS"
          "Australia" "totreswithgold" 2000   1.88e+10 "Total reserves (includes gold, current US$)"  "AUS"
          "Australia" "gdpusd"         2000   4.16e+11 "GDP (current US$)"                            "AUS"
          "Australia" "gdplocal"       2000   1.28e+12 "GDP (constant LCU)"                           "AUS"
          "Australia" "cab"            2001 -2.1038783 "Current account balance (% of GDP)"           "AUS"
          "Australia" "gdpgro"         2001  2.0251274 "GDP growth (annual %)"                        "AUS"
          "Australia" "inflation"      2001  4.4071355 "Inflation, consumer prices (annual %)"        "AUS"
          "Australia" "terms"          2001   70.16765 "Net barter terms of trade index (2015 = 100)" "AUS"
          "Australia" "totresnogold"   2001   1.80e+10 "Total reserves minus gold (current US$)"      "AUS"
          "Australia" "totreswithgold" 2001   1.87e+10 "Total reserves (includes gold, current US$)"  "AUS"
          "Australia" "gdpusd"         2001   3.80e+11 "GDP (current US$)"                            "AUS"
          "Australia" "gdplocal"       2001   1.31e+12 "GDP (constant LCU)"                           "AUS"
          "Australia" "cab"            2002 -4.0431256 "Current account balance (% of GDP)"           "AUS"
          "Australia" "regqual"        2002  1.4211556 "Regulatory Quality: Estimate"                 "AUS"
          "Australia" "goveffect"      2002  1.6591986 "Government Effectiveness: Estimate"           "AUS"
          "Australia" "inflation"      2002  2.9815745 "Inflation, consumer prices (annual %)"        "AUS"
          "Australia" "gdpgro"         2002   3.979634 "GDP growth (annual %)"                        "AUS"
          "Australia" "terms"          2002  71.440575 "Net barter terms of trade index (2015 = 100)" "AUS"
          "Australia" "totresnogold"   2002   2.07e+10 "Total reserves minus gold (current US$)"      "AUS"
          "Australia" "totreswithgold" 2002   2.16e+10 "Total reserves (includes gold, current US$)"  "AUS"
          "Australia" "gdpusd"         2002   3.96e+11 "GDP (current US$)"                            "AUS"
          "Australia" "gdplocal"       2002   1.36e+12 "GDP (constant LCU)"                           "AUS"
          "Australia" "cab"            2003  -6.265829 "Current account balance (% of GDP)"           "AUS"
          "Australia" "regqual"        2003   1.575263 "Regulatory Quality: Estimate"                 "AUS"
          "Australia" "goveffect"      2003   1.773279 "Government Effectiveness: Estimate"           "AUS"
          "Australia" "inflation"      2003   2.732596 "Inflation, consumer prices (annual %)"        "AUS"
          "Australia" "gdpgro"         2003   3.090687 "GDP growth (annual %)"                        "AUS"
          "Australia" "terms"          2003   71.39297 "Net barter terms of trade index (2015 = 100)" "AUS"
          "Australia" "totresnogold"   2003   3.22e+10 "Total reserves minus gold (current US$)"      "AUS"
          "Australia" "totreswithgold" 2003   3.33e+10 "Total reserves (includes gold, current US$)"  "AUS"
          "Australia" "gdpusd"         2003   4.68e+11 "GDP (current US$)"                            "AUS"
          "Australia" "gdplocal"       2003   1.40e+12 "GDP (constant LCU)"                           "AUS"
          "Australia" "cab"            2004  -6.717039 "Current account balance (% of GDP)"           "AUS"
          "Australia" "regqual"        2004  1.7112195 "Regulatory Quality: Estimate"                 "AUS"
          "Australia" "goveffect"      2004   1.984942 "Government Effectiveness: Estimate"           "AUS"
          "Australia" "inflation"      2004  2.3432553 "Inflation, consumer prices (annual %)"        "AUS"
          "Australia" "gdpgro"         2004   4.224322 "GDP growth (annual %)"                        "AUS"
          "Australia" "terms"          2004   78.30724 "Net barter terms of trade index (2015 = 100)" "AUS"
          "Australia" "totresnogold"   2004   3.58e+10 "Total reserves minus gold (current US$)"      "AUS"
          "Australia" "totreswithgold" 2004   3.69e+10 "Total reserves (includes gold, current US$)"  "AUS"
          "Australia" "gdpusd"         2004   6.15e+11 "GDP (current US$)"                            "AUS"
          "Australia" "gdplocal"       2004   1.46e+12 "GDP (constant LCU)"                           "AUS"
          "Australia" "cab"            2005  -6.230184 "Current account balance (% of GDP)"           "AUS"
          "Australia" "regqual"        2005   1.599513 "Regulatory Quality: Estimate"                 "AUS"
          "Australia" "goveffect"      2005  1.7461812 "Government Effectiveness: Estimate"           "AUS"
          "Australia" "inflation"      2005  2.6918316 "Inflation, consumer prices (annual %)"        "AUS"
          "Australia" "gdpgro"         2005   3.154139 "GDP growth (annual %)"                        "AUS"
          "Australia" "terms"          2005   88.37606 "Net barter terms of trade index (2015 = 100)" "AUS"
          "Australia" "totresnogold"   2005   4.19e+10 "Total reserves minus gold (current US$)"      "AUS"
          "Australia" "totreswithgold" 2005   4.33e+10 "Total reserves (includes gold, current US$)"  "AUS"
          "Australia" "gdpusd"         2005   6.96e+11 "GDP (current US$)"                            "AUS"
          "Australia" "gdplocal"       2005   1.51e+12 "GDP (constant LCU)"                           "AUS"
          "Australia" "cab"            2006  -6.184663 "Current account balance (% of GDP)"           "AUS"
          "Australia" "regqual"        2006  1.6237622 "Regulatory Quality: Estimate"                 "AUS"
          "Australia" "goveffect"      2006  1.7078993 "Government Effectiveness: Estimate"           "AUS"
          "Australia" "gdpgro"         2006   2.755298 "GDP growth (annual %)"                        "AUS"
          "Australia" "inflation"      2006  3.5552876 "Inflation, consumer prices (annual %)"        "AUS"
          "Australia" "terms"          2006   98.08377 "Net barter terms of trade index (2015 = 100)" "AUS"
          "Australia" "totresnogold"   2006   5.35e+10 "Total reserves minus gold (current US$)"      "AUS"
          "Australia" "totreswithgold" 2006   5.51e+10 "Total reserves (includes gold, current US$)"  "AUS"
          "Australia" "gdpusd"         2006   7.48e+11 "GDP (current US$)"                            "AUS"
          "Australia" "gdplocal"       2006   1.55e+12 "GDP (constant LCU)"                           "AUS"
          "Australia" "cab"            2007  -7.560151 "Current account balance (% of GDP)"           "AUS"
          "Australia" "regqual"        2007   1.684216 "Regulatory Quality: Estimate"                 "AUS"
          "Australia" "goveffect"      2007  1.8189552 "Government Effectiveness: Estimate"           "AUS"
          "Australia" "inflation"      2007  2.3276112 "Inflation, consumer prices (annual %)"        "AUS"
          "Australia" "gdpgro"         2007   3.773393 "GDP growth (annual %)"                        "AUS"
          "Australia" "terms"          2007  102.81242 "Net barter terms of trade index (2015 = 100)" "AUS"
          "Australia" "totresnogold"   2007   2.48e+10 "Total reserves minus gold (current US$)"      "AUS"
          "Australia" "totreswithgold" 2007   2.69e+10 "Total reserves (includes gold, current US$)"  "AUS"
          "Australia" "gdpusd"         2007   8.55e+11 "GDP (current US$)"                            "AUS"
          "Australia" "gdplocal"       2007   1.61e+12 "GDP (constant LCU)"                           "AUS"
          "Australia" "cab"            2008  -4.873064 "Current account balance (% of GDP)"           "AUS"
          "Australia" "regqual"        2008  1.7660176 "Regulatory Quality: Estimate"                 "AUS"
          "Australia" "goveffect"      2008   1.784768 "Government Effectiveness: Estimate"           "AUS"
          "Australia" "gdpgro"         2008   3.586228 "GDP growth (annual %)"                        "AUS"
          "Australia" "inflation"      2008  4.3502984 "Inflation, consumer prices (annual %)"        "AUS"
          "Australia" "terms"          2008  117.72403 "Net barter terms of trade index (2015 = 100)" "AUS"
          "Australia" "totresnogold"   2008   3.07e+10 "Total reserves minus gold (current US$)"      "AUS"
          "Australia" "totreswithgold" 2008   3.29e+10 "Total reserves (includes gold, current US$)"  "AUS"
          "Australia" "gdpusd"         2008   1.06e+12 "GDP (current US$)"                            "AUS"
          "Australia" "gdplocal"       2008   1.67e+12 "GDP (constant LCU)"                           "AUS"
          "Australia" "cab"            2009  -5.216704 "Current account balance (% of GDP)"           "AUS"
          "Australia" "goveffect"      2009  1.7019638 "Government Effectiveness: Estimate"           "AUS"
          "Australia" "inflation"      2009  1.7711172 "Inflation, consumer prices (annual %)"        "AUS"
          "Australia" "regqual"        2009  1.8169276 "Regulatory Quality: Estimate"                 "AUS"
          "Australia" "gdpgro"         2009  1.8925736 "GDP growth (annual %)"                        "AUS"
          end
          ------------------ copy up to and including the previous line ------------------

          Comment


          • #6
            On the assumption that you have solved your missing values problem in variable id by now, the following works with your example data:
            Code:
            gen `c(obs_t)' obs_no = _n
            levelsof id, local(ids) clean
            foreach i of local ids {
                summ obs_no if id == "`i'"
                local `i'_lbl = series[`r(min)']
            }
            
            drop obs_no
            drop series
            reshape wide var, i(country year) j(id) string
            rename var* *
            foreach v of varlist `ids' {
                label var `v' `"``v'_lbl'"'
            }
            The first "paragraph" of the code captures a list of the values of variable id and prepares labels that can be assigned to them once they become variables after -reshape-, rather than values of id. The variable series in your original data cannot be be preserved as a variable in the wide layout--but the information it carries will be preserved in those variable labels.

            The second paragraph is the -reshape- itself. It is pretty straightforward. The -reshape- is followed by labeling each of the newly created variables with the information that previously corresponded to it in series.

            Comment


            • #7
              Clyde, you make it look so easy! Thank you very much.

              Comment

              Working...
              X