|
⇤ ← Revision 1 as of 2023-06-09 15:36:36
Size: 1401
Comment:
|
← Revision 2 as of 2025-10-24 14:57:15 ⇥
Size: 1536
Comment: Rewrite
|
| Deletions are marked like this. | Additions are marked like this. |
| Line 3: | Line 3: |
| '''Frames''' are in-memory datasets that can be swapped in and out of being the active dataset. | '''Frames''' are in-memory datasets. |
| Line 11: | Line 11: |
| == Definition == | == Description == |
| Line 13: | Line 13: |
| The active dataset is automatically also the `default` frame. It can be renamed like: | Conventionally, Stata only has an active, in-memory dataset. The '''`-frame-`''' command operates as a wrapper for interacting with multiple, in-memory datasets. To list all frames, try `frame dir`. The active dataset is automatically assigned the label `default`. This subcommand also lists sizes (i.e., ''rows x columns'') and dataset labels. To re-label a frames, try: |
| Line 19: | Line 23: |
| A new frame is created like: | To switch between frames, try: |
| Line 22: | Line 26: |
| frame create newframe | frame change newframe |
| Line 24: | Line 28: |
The `frame dir` command lists all frames, their size (as ''number of rows x number of columns''), and the dataset label (if any). |
|
| Line 33: | Line 35: |
| An existing dataset is copied into a new frame like: |
|
| Line 34: | Line 38: |
| frame copy oldframe frame1 frame put foo bar baz, into(frame2) frame put if foo==1, into(frame3) |
frame copy default copied |
| Line 39: | Line 41: |
| `frame1` contains a complete copy of `oldframe`. `frame2` contains all rows and 3 columns of `oldframe`. `frame3` contains all columns and a subset of rows of `oldframe`. | A new, empty frame is created like: |
| Line 42: | Line 44: |
| frame change newframe | frame create myframe |
| Line 45: | Line 47: |
| The alias '''`cwf`''' can be used in the same way. | Rows and columns can be copied from the active dataset into a frame like: {{{ frame put foo bar baz if foo==1, into(myframe) }}} === Clearing Frames === To drop one or more frames, try: |
| Line 51: | Line 63: |
| Note that the active frame cannot be dropped. To truly reset the status of frames, try `frame reset`. | Note that the active dataset cannot be dropped this way. To completely reset the state of frames, try `frame reset`. |
| Line 57: | Line 71: |
| A '''frame scope''' can be entered with `frame FRAMENAME: ` This environment executes within the specified frame and returns to the current frame at the end of the statement. | A '''frame scope''' can be used to run one statement in another frame. Try: {{{ frame newframe: summ foo }}} The frame state returns to the current frame at the end of this statement. |
Stata Frames
Frames are in-memory datasets.
Description
Conventionally, Stata only has an active, in-memory dataset. The -frame- command operates as a wrapper for interacting with multiple, in-memory datasets.
To list all frames, try frame dir. The active dataset is automatically assigned the label default. This subcommand also lists sizes (i.e., rows x columns) and dataset labels.
To re-label a frames, try:
frame rename default oldframe
To switch between frames, try:
frame change newframe
Usage
An existing dataset is copied into a new frame like:
frame copy default copied
A new, empty frame is created like:
frame create myframe
Rows and columns can be copied from the active dataset into a frame like:
frame put foo bar baz if foo==1, into(myframe)
Clearing Frames
To drop one or more frames, try:
frame drop frame1 frame2 frame3
Note that the active dataset cannot be dropped this way.
To completely reset the state of frames, try frame reset.
Frame Scope
A frame scope can be used to run one statement in another frame. Try:
frame newframe: summ foo
The frame state returns to the current frame at the end of this statement.
