User Tools

Site Tools


howtos:workwithdata:import_quick_reference

This is an old revision of the document!


Examples of common import/create calls are provided below.

It is convenient to set up one or more import directory paths up front. For example:

string $importDir= $home + "/V1/primaryData"

Specifying data directly through a parameter

hhVehOwnRelProp_hhs[hhs] = import (; data="1.03 2.01 2.32 2.38 2.41 2.41 2.31")

csv file

This is an example of importing into a very simple mask variable, zoneMask[z], indexed by a single pre-defined informant, zone. Here is the top of the source data file zonesMask.csv:

"zone","maskValue"
201,1
202,1
211,0
212,1
213,0
214,1
.
.
.

And here is the code:

zoneMask[z] = import (; dataFormat=coordinate, fileFormat=text, \
	allCoord=on, delimiter=",", firstLine=2, \
	file=$importDir/zonesMask.csv)

Note:

  • the use of the firstLine=2 parameter to skip over the header row
  • no element name modification is required

Alternatively one may use the heading parameter to skip over the first line:

zoneMask[z] = import (; dataFormat=coordinate, fileFormat=text, \
    allCoord=on, delimiter=",", heading=on, \
    file=$importDir/zonesMask.csv)

tab delimited text odometer (block) format

This format is useful for migrating data between models in a human-readable format, as opposed to binary tool-format files. Note the use of expForm and decimals parameters to preserve precision.

export (immigration[s,ts1,a]; dataFormat=odometer, fileFormat=text, \
	expForm=on, decimals=6, \
	file=$exportDir/immigration.txt)

produces the following (header not shown):

!	sex=male
! 	0		1		2	
"1977"	1.049407e+02	1.314661e+02	1.317941e+02
"1978"	9.129648e+01	1.133035e+02	1.212180e+02
"1979"	8.643492e+01	9.573391e+01	9.366822e+01
"1980"	9.673356e+01	9.806976e+01	9.806976e+01

TOOL file

USUseComByInd_19982008[com_du,indio_du,t_19982008] = import (; \
	format=tool, dataFile=$importDir_ind/USUseComByInd_19982008)
howtos/workwithdata/import_quick_reference.1314283698.txt.gz · Last modified: 2011/08/25 14:48 by marcus.williams