Announcement

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

  • forvalue index included in csv file name

    Hey everyone,

    I'm attempting to assemble a panel dataset using a handful of CSV files each of which correspond to a single year. Each file has the same name ending in the year the data corresponds to. That is my csv files are "data1992.csv", "data1993.csv", eta. I just want to import them, generate a variable corresponding to the year, and then save the file as .dta. My current attempt is

    forvalues i = 1992(1)2000 {
    import delimited "hd'i'.csv"
    gen year='i'
    save tem'i'.dta, replace
    }

    Thanks for anyone's help or advice!

  • #2
    You need to use the backtick character before your local macro, namely
    Code:
    forvalues i = 1992(1)2000 {
    import delimited "hd`i'.csv"
    gen year=`i'
    save tem`i'.dta, replace
    }
    On US keyboards, the backtick character (`) is usually on the upper left of the keyboard, often sharing a key with the tilde (~) character.
    David Radwin
    Senior Researcher, California Competes
    californiacompetes.org
    Pronouns: He/Him

    Comment

    Working...
    X