Announcement

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

  • Need help regarding STATA's putexcel command

    Hi all,

    I am working with macroeconomic variables of different economies in Euro area and need to transfer yld_spread and inf_exp of every country and every year in an excel file. So the excel file will contain four different columns: Year, Country, Yld_spread and inf_exp. It will be something like this:

    2010 EU ....x1... y1....
    2011 EU ...x2.. ...y2....
    .
    .
    2010 DK .....x1.... ...y1...
    2011 DK .....x1.... ...y1...
    ...
    2016 DK .... x7.... ....y7....

    x_i and y_i are the yld_spread and inf_exp (arranged in two separate columns) of that country and the particular year and i = 2010, ...., 2016.

    The code I have used is:

    putexcel A1=("year") B1=("Country") C1=("yld_spread") D1=("inf_exp")
    local row=2
    foreach num of numlist 2010/2016 {
    putexcel A`row'=("`num'")
    putexcel B`row'=(country)
    putexcel C`row'=(yld_spread) if year==`num'
    putexcel D`row'=(inf_exp) if year==`num'
    local ++row
    }

    But Stata is giving an error. Can someone point out to my mistake and help me write the right code?

    Thanks,
    Amit

  • #2
    I have never used this command but think I can make some comments.

    Note that your code is asking for eight rows, row 1 and one for each year 2010 ... 2016. That's a long way from what you say you want.

    Also, you're expecting Stata to evaluate

    country

    and put the values in column B, row 2 onwards. Further, if is not allowed with putexcel. These two problems are one and the same you have to tell the command exactly what you want put where. It won't work out which data you want.

    All that said, it seems that you want a copy in Excel of your data. Writing code to export the data cell by cell is less attractive than any other solution except copying and pasting cell by cell. I'd check out export excel.

    Comment

    Working...
    X