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: Need help with Stata Programming


From   Nick Cox <[email protected]>
To   "[email protected]" <[email protected]>
Subject   Re: st: Need help with Stata Programming
Date   Thu, 30 May 2013 19:58:24 +0100

Nick
[email protected]

local ds1 "D:\_Dummy\multiple\1\auto_1.dta"
local ds2 "D:\_Dummy\multiple\2\auto_2.dta"
local ds3 "D:\_Dummy\multiple\3\auto_3.dta"
local all ds1 ds2 ds3
local y = 1999
foreach x in `all'{
use ``x'',clear
include "D:\_Dummy\multiple\4\mpg.do"
include "D:\_Dummy\multiple\5\sum.do"
local ++y
gen year = "`y' "
save ``x''_new.dta,replace
}

local ++y

could be

local y = `y' + 1

The whole thing could be shorter.

> ************************************************
> NOW MY  NEW TASK/PROBLEM:
> I want to create a string variable  "year" which needs to be 2000 for
> auto_1.dta, 2001 for auto_2.dta,2002 for auto_3.dta etc
> Is could open each dataset and create it myself  before starting a  the loop.
> But is there a way to create one OR more  variables with different
> values for different datasets??  within a loop
*
*   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