Announcement

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

  • Writing a macro variable into a csv file

    I specify here that i'm truly a neophyte in this language and i'm kind of struggling with easy stuff.
    What i want to do here is to do some test and then calculate how many times it takes to stata to do it. I want to report my result into a csv file.
    Code:
     
     import delimited "C:\Users\Olivier\Desktop\Zebrys\data\integ_narr_1_unif_bina_1.csv", encoding(Big5)   timer on 1 /*moyenne timer*/ tabstat (v1-v128), stat(mean) timer off 1   timer on 2 /*median timer */ tabstat (v1-v128), stats(median) timer off 2  timer list  di `r(t1)' input str10 fichier  temps str10 action     "bina" `r(t1)' "mean" end  export delimited fichier temps action using "cr_etape1", replace timer clear /* On vide le timer et la liste */  clear
    And in fact Stata cannot read my variable, i obtain this error :
    '`' cannot be read as a number
    Thanks for your help

  • #2
    A clearer presentation of the code in post #1
    Code:
    import delimited "C:\Users\Olivier\Desktop\Zebrys\data\integ_narr_1_unif_bina_1.csv", encoding(Big5) 
    
    timer on 1 /*moyenne timer*/
    tabstat (v1-v128), stat(mean)
    timer off 1 
    
    timer on 2 /*median timer */
    tabstat (v1-v128), stats(median)
    timer off 2
    
    timer list 
    di `r(t1)'
    input str10 fichier  temps str10 action    
    "bina" `r(t1)' "mean"
    end
    
    export delimited fichier temps action using "cr_etape1", replace
    timer clear /* On vide le timer et la liste */
    
    clear
    Your code failed because the data presented to your input command cannot include local macros.

    A better approach to saving your results to Excel would be to use the putexcel command. The following untested code may show you a useful direction.
    Code:
    putexcel set "cr_etape1". replace
    putexcel A1 = "bina"
    putexcel A2 = `r(t1)'
    putexcel A3 = "mean"
    putexcel save

    Comment

    Working...
    X