foreach - Import 50+ .dat files into SPSS using a loop -


I have to import many .dat files (one for each state of the United States for several years) in SPAT and then Save each one to a star. File files such as Dta Datasets are standardized names with year and state abbreviation, e.g. Data_2000_AL.dat. I have SPSS code for reading and formatting each file, one by one, you specify the path for each state-year file and then run the code.

In Stata, I set up the projection / foreach each year and loops to run through the state, that is:

< Pre> forvalues ​​y = 2000/2010 {foreach s al ak az AR CA ... {[code to run data. Read / Format files Files] to save data __'_ '' data, replace}}

Unfortunately, I only have SPSS code (not stata dictionary files), and I'm familiar with SPSS Is there any way to replicate the above stat code in SPSS?

You can either use the macro or this one on the way to use the Python macro A brief example is

  Define! State Loop (! POSITIONAL =! CMDEND)! DO! I! IN! (! 1)! DO! J = 2000! Until 2002! Late! F =! Coat (! Conkit (! I, "_",! J, ".dat")) ECO! F. * You import / export here! Drop! Interval! ! State Loop PA NY NJ  

It prints later:

  PA_2000.dat PA_2001.dat PA_2002.dat NY_2000.dat NY_2001.dat NY_2002.dat NJ_2000.dat NJ_2001.dat NJ_2002.dat  

This is just the macro operators ! Using the CONCAT , each string is required for each state and looping on it.

If you do this in Python then you can use spss.Submit and similar string substitution:

  BEGIN program Imported SPSS for Python S: F = J + "_" + AR (2000 + I) SPSS SUVMT ("" "S") = ["PA", "NY", "NJ" "ECO "% S". " End the ""% (f) program  

Comments

Popular posts from this blog

python - Overriding the save method in Django ModelForm -

html - CSS autoheight, but fit content to height of div -

qt - How to prevent QAudioInput from automatically boosting the master volume to 100%? -