Bookmark and Share

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   Matthew White <mwhite@poverty-action.org>
To   statalist@hsphsun2.harvard.edu
Subject   Re: st: inputting data via a series of nested loops
Date   Tue, 23 Jul 2013 19:55:11 -0400

Hi Ben,

How about -post-?

Best,
Matt

On Tue, Jul 23, 2013 at 7:30 PM, Ben Hoen <bhoen@lbl.gov> wrote:
> Thanks Sergiy,
>
> I actually did mean -input- as in "input x y".  I can see the problem with
> what I wrote given what you mention about the data immediately following the
> -input- command.  Is there any way to build a dataset as I had hoped using
> loops of numbers/strings?  For example, can I display, and then use the
> contents of the display for the data I wish to enter?
>
> I am grasping at straws here, but I have a large patterned dataset (similar
> to the one I mentioned) that I need to build as a template and it would be
> useful to use loops to build it.  Then again, maybe there is a much
> different way than using -input-...
>
> Thanks, for any advice you or others might offer.  Best,
>
> Ben
>
> Ben Hoen
> LBNL
> Office: 845-758-1896
> Cell: 718-812-7589
>
>
> -----Original Message-----
> From: owner-statalist@hsphsun2.harvard.edu
> [mailto:owner-statalist@hsphsun2.harvard.edu] On Behalf Of Sergiy Radyakin
> Sent: Tuesday, July 23, 2013 4:13 PM
> To: statalist@hsphsun2.harvard.edu
> Subject: Re: st: inputting data via a series of nested loops
>
> 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 <bhoen@lbl.gov> 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
>> bhoen@lbl.gov
>> 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/
>
> *
> *   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/



-- 
Matthew White
Senior Project Associate
Innovations for Poverty Action
101 Whitney Avenue, New Haven, CT 06510 USA
www.poverty-action.org
*
*   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/


© Copyright 1996–2018 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   Site index