Announcement

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

  • How can I treat prefix of file name and variable name?

    I must analyze the SOEP data files using stata. The name of data file is pgen.dta. There are prefixes a, b, c ,d …z for year from 1984 to 2009 and ba, bb, bc, bd for year 2010, 2011, 2012 and 2013 respectively. In these files, there are also same characters in variable names indicating survey year like aberwzeit, bberwzeit… There are also postfixes in certain variable names using last 2 digit number of survey year such as nation84 designating survey year 1984.
    I must also analyze pequiv.dta which also named like pgen.dta
    I must make these file (total 60 files) into just one file to make the panel data file. First of all I want to make pgen.dta files into pgen1.dta files keeping only interesting observations and fields.

    For this job, I made the following ado file.
    ==============================
    capture program drop preex1
    program define preex1
    local fileprefix a b c d e f g h I j k l m n o p q r s t u v w x y z //
    ba bb bc bd
    foreach v of local fileprefix {
    use `v'pgen, clear
    keep if (nation?? ==1) //if "`v'"=a then ??=84 else if "`v'"=b then ??=85 …..
    keep if (emplst?? == 1 | emplst?? ==2)
    keep persnr emplst?? expft?? expue?? “`v’”+erwzeit betr?? nace?? “`v’”+vebzeit nation?? “`v’”+bilzeit labgro??
    save `v’pgen1.dta, replace
    }
    exit
    ===============
    please comment for me for above underlined line!

  • #2
    Hi Jinhyun,

    adding the following three lines after your "foreach"-statement could help; afterwards, the survey year can be accessed via the local macro `year'
    Code:
    local year : list posof `"`v'"' in fileprefix
    local year=`year'+1983
    local year=substr(`"`year'"',3,.)
    I hope this helps a bit; for details on how to best handle the GSOEP data, you should probably contact the GSOEP staff at the DIW.

    Regards
    Bela

    PS: In your code, it should read "///" instead of "//" at the end of line 3
    Last edited by Daniel Bela; 07 Aug 2016, 06:43. Reason: code adjustments to work for years later than 1999

    Comment


    • #3
      Thank Daniel Bela! You help me a lot!!!!!

      Comment

      Working...
      X