Notice: On April 23, 2014, Statalist moved from an email list to a forum, based at statalist.org.
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: st: inputting data via a series of nested loops
From
Sergiy Radyakin <[email protected]>
To
"[email protected]" <[email protected]>
Subject
Re: st: inputting data via a series of nested loops
Date
Tue, 23 Jul 2013 16:12:44 -0400
The command -input- assumes the data follows immediately in the program:
input x y
10 20
20 70
end
You are probably confusing it with a command -input- in some other
languages, like BASIC, where it serves the purpose of requesting
values from the user.
In Stata you can use the -display- command for that:
display "Enter value for X:" _request(x)
display `"$x"'
Best, Sergiy
On Tue, Jul 23, 2013 at 2:46 PM, Ben Hoen <[email protected]> wrote:
> Hi all,
>
> I am trying to encourage Stata to enter data into a new dataset via a loop
> in an ado file. I was not able to find anything in the archives that fit my
> situation (though I did find this:
> http://www.stata.com/statalist/archive/2010-07/msg00425.html).
>
> For example, say I wanted to end up with this as my dataset:
>
> type place time
> a 1 1
> a 1 2
> a 2 1
> a 2 2
> b 1 1
> b 1 2
> b 2 1
> b 2 2
> c 1 1
> c 1 2
> c 2 1
> c 2 2
>
> I have tried the following which works:
>
> local name "a b c"
> foreach n of local name {
> forvalues time = 1/2 {
> forvalues place = 1/2 {
> display "`n' `time' `place'"
> }
> }
> }
> end
> *
>
> The results:
>
>
> . do "B:\temp\STD08000000.tmp"
>
> . local name "a b c"
>
> . foreach n of local name {
> 2. forvalues time = 1/2 {
> 3. forvalues place = 1/2 {
> 4. display "`n' `time' `place'"
> 5. }
> 6. }
> 7. }
> a 1 1
> a 1 2
> a 2 1
> a 2 2
> b 1 1
> b 1 2
> b 2 1
> b 2 2
> c 1 1
> c 1 2
> c 2 1
> c 2 2
>
> And therefore I hoped the following would work:
>
> input name time place
> local name "a b c"
> foreach n of local name {
> forvalues time = 1/2 {
> forvalues place = 1/2 {
> `n' `time' `place'
> }
> }
> }
> end
> *
>
> But, for which I get:
>
>
> . do "B:\temp\STD08000000.tmp"
>
> . input name time place
>
> name time place
> 1. local name "a b c"
> 'local' cannot be read as a number
> 1. foreach n of local name {
> 'foreach' cannot be read as a number
> 1. forvalues time = 1/2 {
> 'forvalues' cannot be read as a number
> 1. forvalues place = 1/2 {
> 'forvalues' cannot be read as a number
> 1. `n' `time' `place'
> '`' cannot be read as a number
> 1. }
> '' cannot be read as a number}
> 1. }
> '' cannot be read as a number}
> 1. }
> '' cannot be read as a number}
> 1. end
>
> . *
> .
> end of do-file
>
>
> Any ideas how to correct?
>
> Thanks, in advance,
>
> Ben
>
>
> Ben Hoen
> Staff Research Associate
> Lawrence Berkeley National Laboratory
> Office: 845-758-1896
> Cell: 718-812-7589
> [email protected]
> http://emp.lbl.gov/staff/ben-hoen
>
> Visit our publications at:
> http://emp.lbl.gov/reports/re
>
> Sign up for our email list to receive publication notifications at:
> https://spreadsheets.google.com/a/lbl.gov/spreadsheet/viewform?formkey=dGlFS
> 1U1NFlUNzQ1TlBHSzY2VGZuN1E6MQ
>
>
>
>
>
> *
> * For searches and help try:
> * http://www.stata.com/help.cgi?search
> * http://www.stata.com/support/faqs/resources/statalist-faq/
> * http://www.ats.ucla.edu/stat/stata/
*
* For searches and help try:
* http://www.stata.com/help.cgi?search
* http://www.stata.com/support/faqs/resources/statalist-faq/
* http://www.ats.ucla.edu/stat/stata/