public final class Frame extends Object
Frame
,
which provides many methods for accessing the underlying Stata frame. If the
underlying frame is renamed from Stata, Mata, etc., then access to the frame
from its object will be lost. For more information about Stata frames, see
help frames in Stata.
All variable and observation numbering begins at 1 unless otherwise stated.
Modifier and Type | Method and Description |
---|---|
int |
addVarByte(String varname)
Add a variable of type byte to the frame.
|
int |
addVarDouble(String varname)
Add a variable of type double to the frame.
|
int |
addVarFloat(String varname)
Add a variable of type float to the frame.
|
int |
addVarInt(String varname)
Add a variable of type int to the frame.
|
int |
addVarLong(String varname)
Add a variable of type long to the frame.
|
int |
addVarStr(String varname,
int length)
Add a variable of type str to the frame.
|
int |
addVarStrL(String varname)
Add a variable of type strL to the frame.
|
int |
allocateStrL(StrLConnector dsc,
long size)
Allocate a strL so that a buffer can be stored using
writeBytes ; the contents
of the strL will not be initialized. |
int |
allocateStrL(StrLConnector dsc,
long size,
boolean binary)
Allocate a strL so that a buffer can be stored using
writeBytes ; the contents
of the strL will not be initialized. |
int |
changeToCWF()
Set the
Frame as the current working frame in
Stata. |
Frame |
clone(String newName)
|
static Frame |
connect(String name)
Connect to an existing frame in Stata and return a new
Frame instance that can be used to access it. |
static Frame |
create(String name)
Create a new frame in Stata and return a new
Frame
instance that can be used to access it. |
int |
drop()
Drop the frame in Stata.
|
int |
dropVar(int var)
Drop the variable at the specified variable index.
|
String |
getFormattedValue(int var,
long obs,
boolean bValueLabel)
Read a value from the frame, applying its display format.
|
static String |
getFrameAt(int index)
Utility method for getting the name of a Stata frame at a given index.
|
static int |
getFrameCount()
Utility method for getting the number of frames in Stata.
|
double |
getNum(int var,
long obs)
Read a numeric value from the frame.
|
long |
getObsTotal()
Get the number of observations in the frame.
|
String |
getStr(int index,
long obs)
Read a string value from the frame.
|
String |
getStrf(int index,
long obs)
Read a string value from the frame.
|
int |
getStrVarWidth(int var)
Get the width of a variable of type str.
|
int |
getType(int var)
Get the numeric data type for the specified variable.
|
int |
getVarCount()
Get the number of variables in the frame.
|
String |
getVarFormat(int var)
Get the format for a variable in the frame.
|
int |
getVarIndex(String varname)
Look up the variable index for the specified variable name in the frame.
|
String |
getVarLabel(int var)
Get the label for a variable in the frame.
|
String |
getVarName(int var)
Get the variable name at a given variable index.
|
boolean |
isVarTypeStr(int var)
Test if a variable is of type str.
|
boolean |
isVarTypeString(int var)
Test if a variable is string or numeric.
|
boolean |
isVarTypeStrL(int var)
Test if a variable is of type strL.
|
int |
readBytes(StrLConnector dsc,
byte[] b)
Read a sequence of bytes from a strL in the current Stata dataset.
|
int |
readBytes(StrLConnector dsc,
byte[] b,
int off,
int len)
Read a sequence of bytes from a strL in the current Stata dataset.
|
int |
rename(String newName)
Rename the frame in Stata.
|
int |
renameVar(int var,
String newname)
Rename a variable.
|
int |
setObsTotal(long obs)
Set the number of observations in the frame.
|
int |
setVarFormat(int var,
String format)
Set the format for a variable in the frame.
|
int |
setVarLabel(int var,
String label)
Set the label for a variable in the frame.
|
int |
storeBytes(int var,
long obs,
byte[] bytes,
boolean binary)
Store a byte buffer to a strL in the frame.
|
int |
storeNum(int var,
long obs,
double value)
Store a numeric value in the frame.
|
int |
storeNumFast(int var,
long obs,
double value)
Store a numeric value in the frame.
|
int |
storeStr(int var,
long obs,
String value)
Store a string value in the frame.
|
int |
storeStrf(int var,
long obs,
String value)
Store a string value in the frame.
|
int |
storeStrfFast(int var,
long obs,
String value)
Store a string value in the frame.
|
void |
updateModified()
Inform Stata that the frame's data has been modified.
|
int |
writeBytes(StrLConnector dsc,
byte[] b)
Write a byte buffer to a strL in the current Stata dataset; the
strL must be allocated using
allocateStrL before
calling this method. |
int |
writeBytes(StrLConnector dsc,
byte[] b,
int off,
int len)
Write
len bytes from the specified byte buffer starting at
offset off to a strL in the current Stata dataset;
the strL must be allocated using
allocateStrL before
calling this method. |
@Synchronized public int addVarByte(String varname)
varname
- Name of the variable to be created.@Synchronized public int addVarDouble(String varname)
varname
- Name of the variable to be created.@Synchronized public int addVarFloat(String varname)
varname
- Name of the variable to be created.@Synchronized public int addVarInt(String varname)
varname
- Name of the variable to be created.@Synchronized public int addVarLong(String varname)
varname
- Name of the variable to be created.@Synchronized public int addVarStr(String varname, int length)
varname
- Name of the variable to be created.length
- Initial size of the variable. If the length is greater
than Data.getMaxStrLength()
, then a variable of type
strL will be created.@Synchronized public int addVarStrL(String varname)
varname
- Name of the variable to be created.@Synchronized public int allocateStrL(StrLConnector dsc, long size) throws IOException
writeBytes
; the contents
of the strL will not be initialized. By default, the data will be
marked as binary.dsc
- The StrLConnector representing a strL.size
- The size in bytes.IOException
- Throws an IOException if an error occurs.@Synchronized public int allocateStrL(StrLConnector dsc, long size, boolean binary) throws IOException
writeBytes
; the contents
of the strL will not be initialized.dsc
- The StrLConnector representing a strL.size
- The size in bytes.binary
- Mark the data as binary. Note that if the data are not
marked as binary, Stata expects that the data be UTF-8
encoded. An alternate approach is to call
storeStr
, where the
encoding is automatically handled.IOException
- Throws an IOException if an error occurs.@Synchronized public int changeToCWF()
Frame
as the current working frame in
Stata. The current working frame in Stata can be accessed using
Data
if desired.@Synchronized public Frame clone(String newName) throws FrameException
Frame
instance by cloning the current
Frame
and its contents. This results in a new frame
in Stata.newName
- The name of the new frame to be created.Frame
that corresponds to the newly
cloned frame in Stata.FrameException
- If the cloning of the frame fails.@Synchronized public static Frame connect(String name) throws FrameException
Frame
instance that can be used to access it.name
- Name of an existing Stata frame.Frame
that corresponds to the existing
frame in Stata.FrameException
- If the frame does not already exist in Stata or if
connecting to the frame fails.@Synchronized public static Frame create(String name) throws FrameException
Frame
instance that can be used to access it.name
- Name of the Stata frame to create.Frame
that corresponds to the new
frame in Stata.FrameException
- If the creation of the new frame in Stata fails.@Synchronized public int drop()
@Synchronized public int dropVar(int var)
var
- Variable to drop.@Synchronized public String getFormattedValue(int var, long obs, boolean bValueLabel)
var
- Variable to access.obs
- Observation to access.bValueLabel
- Use the value label when available.String
.@Synchronized public static String getFrameAt(int index)
index
- The index for a frame.@ThreadSafe public double getNum(int var, long obs)
var
- Variable to access.obs
- Observation to access.@ThreadSafe public long getObsTotal()
@Synchronized public String getStr(int index, long obs)
index
- Variable to access.obs
- Observation to access.String
. Returns null if an error occurs.@ThreadSafe public String getStrf(int index, long obs)
index
- Variable to access.obs
- Observation to access.String
. Returns null if an error occurs.@ThreadSafe public int getStrVarWidth(int var)
var
- The index of the variable to test.@ThreadSafe public int getType(int var)
var
- Variable to access.TYPE_BYTE
,
TYPE_INT
,
TYPE_LONG
,
TYPE_FLOAT
,
TYPE_DOUBLE
,
TYPE_STR
, or
TYPE_STRL
.@ThreadSafe public int getVarCount()
@ThreadSafe public String getVarFormat(int var)
var
- Index of the variable to look up.@Synchronized public int getVarIndex(String varname)
varname
- Name of the variable.@ThreadSafe public String getVarLabel(int var)
var
- Index of the variable to look up.@ThreadSafe public String getVarName(int var)
var
- Index of the variable to look up.@ThreadSafe public boolean isVarTypeStr(int var)
var
- The index of the variable to test.@ThreadSafe public boolean isVarTypeString(int var)
var
- The index of the variable to test.@ThreadSafe public boolean isVarTypeStrL(int var)
var
- The index of the variable to test.@Synchronized public int readBytes(StrLConnector dsc, byte[] b) throws IOException
dsc
- The StrLConnector representing a strL.b
- The buffer into which the data are read.IOException
- Throws an IOException if an error occurs.@Synchronized public int readBytes(StrLConnector dsc, byte[] b, int off, int len) throws IOException
dsc
- The StrLConnector representing a strL.b
- The buffer into which the data are read.off
- The start offset in the destination array b.len
- The maximum number of bytes read.IOException
- Throws an IOException if an error occurs.@Synchronized public int rename(String newName)
newName
- Name of the new frame.@Synchronized public int renameVar(int var, String newname)
var
- Index of the variable to rename.newname
- New variable name.@Synchronized public int setObsTotal(long obs)
obs
- The number of observations to set.@Synchronized public int setVarFormat(int var, String format)
var
- Index of the variable to format.format
- New format.@Synchronized public int setVarLabel(int var, String label)
var
- Index of the variable to label.label
- New label.@Synchronized public int storeBytes(int var, long obs, byte[] bytes, boolean binary)
allocateStrL
before using this method.var
- Variable to access.obs
- Observation to access.bytes
- Bytes to store.binary
- Mark the data as binary.@Synchronized public int storeNum(int var, long obs, double value)
var
- Variable to access.obs
- Observation to access.value
- Value to store.@ThreadSafe public int storeNumFast(int var, long obs, double value)
Frame.updateModified()
.var
- Variable to access.obs
- Observation to access.value
- Value to store.@Synchronized public int storeStr(int var, long obs, String value)
var
- Variable to access.obs
- Observation to access.value
- Value to store.@Synchronized public int storeStrf(int var, long obs, String value)
var
- Variable to access.obs
- Observation to access.value
- Value to store.@ThreadSafe public int storeStrfFast(int var, long obs, String value)
Frame.updateModified()
. If the string is longer than the current
storage length, then the string will be truncated.var
- Variable to access.obs
- Observation to access.value
- Value to store.@Synchronized public void updateModified()
@Synchronized public int writeBytes(StrLConnector dsc, byte[] b)
allocateStrL
before
calling this method. The buffer size may be smaller than the allocation
size for the strL so that calling this method multiple times will
write the data in chunks. The current position of each write will be
automatically maintained. Writing beyond the allocation size is not
permitted.dsc
- The StrLConnector representing a strL.b
- The buffer holding the data to store.@Synchronized public int writeBytes(StrLConnector dsc, byte[] b, int off, int len)
len
bytes from the specified byte buffer starting at
offset off
to a strL in the current Stata dataset;
the strL must be allocated using
allocateStrL
before
calling this method. The buffer size may be smaller than the allocation
size for the strL so that calling this method multiple times will
write the data in chunks. The current position of each write will be
automatically maintained. Writing beyond the allocation size is not
permitted.dsc
- The StrLConnector representing a strL.b
- The buffer holding the data to store.off
- The offset into the buffer.len
- The number of bytes to write.@Synchronized public static int getFrameCount()