Announcement

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

  • J contains missing vals for reshape

    I am studying the causal effect of this cheery policy in Romania on infant mortality rates, and I need to reshape this dataset the astute geniuses in.... Russia, I guess, made into a wide dataset. Why datasets are made like this is beyond me.



    Anyways, when I try this though, I get "variable j contains all missing values". I don't understand. J is meant to be the new variable.... and id doesn't exist yet. Why do I get this error?

    NOTE: I want the Country to be the unique ID variable such that we've got panel data. Just to be clear.

    Code:
    import exc "http://www.demoscope.ru/weekly/app/app4009.xls", clear first cellrange(C8:BG47)
    cls
    
    loc country Australia Austria Belarus Belgium Bulgaria BH UK Hungary Germany Greece Denmark Ireland Spain Italy Canada Korea Latvia Lithuania Macedonia Moldova Netherlands NZ Norway Poland Portugal Russia Romania Serbia Slovakia Slovenia USA Ukraine Finland France Croatia Montenegro Czech Switzerland Sweden Estonia Japan
    
    rename (Австралия-Япония) (`country')
    
    rename * country_*
    
    rename country_C year
    
    drop country_AS-country_BG
    cls
    
    greshape long country_, i(year) j(id)
    Note that I use the user written command greshape, but the syntax is the exact same as normal reshape.
    Last edited by Jared Greathouse; 10 May 2022, 12:54.

  • #2
    There are two problems. First, the values which would go into the j variable are strings, so you need to specify the string option in your reshape command. Second, one of your variables has commas instead of bullets, so you need to fix that:

    Code:
    import exc "http://www.demoscope.ru/weekly/app/app4009.xls", clear first cellrange(C8:BG47)
    cls
    
    loc country Australia Austria Belarus Belgium Bulgaria BH UK Hungary Germany Greece Denmark Ireland Spain Italy Canada Korea Latvia Lithuania Macedonia Moldova Netherlands NZ Norway Poland Portugal Russia Romania Serbia Slovakia Slovenia USA Ukraine Finland France Croatia Montenegro Czech Switzerland Sweden Estonia Japan
    
    rename (Австралия-Япония) (`country')
    
    rename * country_*
    
    rename country_C year
    
    drop country_AS-country_BG
    cls
    
    replace country_Canada = subinstr(country_Canada,",",".",.)
    destring country_*, replace 
    
    greshape long country_, i(year) j(id) str

    Comment


    • #3
      This worked, thanks so much! Ali Atia

      Comment

      Working...
      X