Announcement

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

  • Request for help

    Is there anyone who can help me create a loop from this:

    set more off
    clear all
    foreach x of numlist 2/3 6 {
    *display `x'
    odbc load, table("individus") noquote ///
    conn("DRIVER={MySQL ODBC 8.0 Unicode Driver};SERVER=localhost;DATABASE=enq_tab_00`x';UI D=Christophe;PWD=Christmaevahope;") clear
    save "D:\FTHM_DEP_RDC\LISUNGI\RSU\WAMPSERVER\enq_tab\in dividus_enq_tab_00`x'.dta", replace
    }
    *
    foreach x of numlist 12 23 27 53 58 60 64 71 79 82 85 87 90 98 {
    *display `x'
    odbc load, table("individus") noquote ///
    conn("DRIVER={MySQL ODBC 8.0 Unicode Driver};SERVER=localhost;DATABASE=enq_tab_0`x';UID =Christophe;PWD=Christmaevahope;") clear
    save "D:\FTHM_DEP_RDC\LISUNGI\RSU\WAMPSERVER\enq_tab\in dividus_enq_tab_0`x'.dta", replace
    }
    *
    foreach x of numlist 100 108 116 127 134 142 {
    *display `x'
    odbc load, table("individus") noquote ///
    conn("DRIVER={MySQL ODBC 8.0 Unicode Driver};SERVER=localhost;DATABASE=enq_tab_`x';UID= Christophe;PWD=Christmaevahope;") clear
    save "D:\FTHM_DEP_RDC\LISUNGI\RSU\WAMPSERVER\enq_tab\in dividus_enq_tab_`x'.dta", replace
    }



    Please help me, please.

  • #2
    Welcome to the Stata Forum/ Statalist.

    Please read the FAQ.

    There you’ find how to share data/command/output.

    Also, there are some tips about creating an informative title.

    This is the best approach to entail an insightful reply.
    Best regards,

    Marcos

    Comment


    • #3
      Following on the advice from Marcos, it simply is not clear from your statement in post #1 what the problem is that you seek our help with. You seem to have three loops that have no immediately obvious problem.

      When you review the Statalist FAQ linked to from the top of the page, note especially sections 9-12 on how to best pose your question. It's particularly helpful to copy commands and output from your Stata Results window and paste them into your Statalist post using code delimiters [CODE] and [/CODE], and to use the dataex command to provide sample data, as described in section 12 of the FAQ.

      Section 12.1 is particularly pertinent

      12.1 What to say about your commands and your problem

      Say exactly what you typed and exactly what Stata typed (or did) in response. N.B. exactly!
      ...
      Never say just that something "doesn't work" or "didn't work", but explain precisely in what sense you didn't get what you wanted.

      Comment


      • #4
        Thank you for your reply. I want to combine the three loops (one character, two and three) into one loop. Thank's for your help

        Comment


        • #5
          Here is an example that demonstrates how to create your local macro x as a 3-digit number with leading zeros.
          Code:
          . foreach n of numlist 1/3 21/23 321/323 {
            2. local x : display %03.0f `n'
            3. display " n is `n' and x is `x' "
            4. }
           n is 1 and x is 001 
           n is 2 and x is 002 
           n is 3 and x is 003 
           n is 21 and x is 021 
           n is 22 and x is 022 
           n is 23 and x is 023 
           n is 321 and x is 321 
           n is 322 and x is 322 
           n is 323 and x is 323

          Comment


          • #6

            See also https://www.stata-journal.com/sjpdf....iclenum=pr0051

            Comment


            • #7
              Many thanks to William and Nick. My problem is solved.

              Comment

              Working...
              X