Stata+Concepts+&+Commands

 log using "Read_GSS_Data.txt", text replace  /* Create a subset of variables and cases from the GSS */  #delimit ;  use year  cohort  socbar  socrel  socommun  socfrend  race  age  sex  educ  attend  marital  childs <span style="font-family: courier new,monospace;"> premarsx <span style="font-family: courier new,monospace;"> reliten <span style="font-family: courier new,monospace;"> polviews <span style="font-family: courier new,monospace;"> region <span style="font-family: courier new,monospace;"> sexfreq if race!=3 using http://terpconnect.umd.edu/~smilex3/GSS-Cumulative-72-10.dta, clear; <span style="font-family: courier new,monospace;"> #delimit cr <span style="font-family: courier new,monospace;"> log close ||
 * <span style="font-family: courier new,monospace;">capture log close

For more Stata tips see the SOCY602 Web site

Remapping the Function Keys in Stata
Stata allows you to use global macros to remap the keyboard keys to any value you want, for example, a Stata command you use frequently. I look at the SOCY498C Stata materials frequently and so have created a shortcut key to get there. The following command reprograms the F7 key to access the Stata course materials:

global F7 net from http://terpconnect.umd.edu/~smilex3/stata;

This command can be entered every time you start Stata or put into a profile.do file and executed when you start Stata. See Tip #9 for additional information about setting up personal Stata defaults.

See macro, keyboard , Stata Journal(reprogram F-Keys).

Stata commands from day #1:
<span style="font-family: 'Courier New',Courier,monospace;">sysuse <span style="font-family: 'Courier New',Courier,monospace;">list <span style="font-family: 'Courier New',Courier,monospace;">browse <span style="font-family: 'Courier New',Courier,monospace;">tab <span style="font-family: 'Courier New',Courier,monospace;">log <span style="font-family: 'Courier New',Courier,monospace;">help <span style="font-family: 'Courier New',Courier,monospace;">drop <span style="font-family: 'Courier New',Courier,monospace;">hist <span style="font-family: 'Courier New',Courier,monospace;">summ <span style="font-family: 'Courier New',Courier,monospace;">clear <span style="font-family: 'Courier New',Courier,monospace;">set more <span style="font-family: 'Courier New',Courier,monospace;">if/in/varlist

Please read the following set of definitions taken from the statlist listserv (<span style="font-family: 'Courier New',Courier,monospace;">[]):

<span style="font-family: 'Courier New',Courier,monospace;">st: Variables, macros, locals, globals
<span style="font-family: 'Courier New',Courier,monospace;">From "Nick Cox" <n.j.cox@durham.ac.uk> <span style="font-family: 'Courier New',Courier,monospace;"> To <statalist@hsphsun2.harvard.edu> <span style="font-family: 'Courier New',Courier,monospace;"> Subject st: Variables, macros, locals, globals <span style="font-family: 'Courier New',Courier,monospace;"> Date Thu, 28 Aug 2008 15:08:36 +0100

<span style="font-family: 'Courier New',Courier,monospace;"> Some recent threads indicate that even some people trying to write Stata programs can get very confused on what exactly is a variable, etc.

<span style="font-family: 'Courier New',Courier,monospace;"> At some point it becomes extremely inefficient not to read the help files and manuals and try to internalise Stata's terminology. Most importantly, your questions may not make much sense to other people otherwise. There will be lots of little pleasurable bursts of understanding as stuff that puzzled you makes sense for the first time.

<span style="font-family: 'Courier New',Courier,monospace;"> Here is an attempt to put down some basics, with particular stress on some common confusions. Contrary to appearances, I won't try to tell the complete truth, as explaining some minor exceptions or complications would probably help less than keeping quiet about them. Also, a glossary could go on and on. In this case, I stopped short of explaining scalars, or matrices, or ....

__<span style="font-family: 'Courier New',Courier,monospace;"> Metarules __ <span style="font-family: 'Courier New',Courier,monospace;"> 1. In Stata, the terminology used by StataCorp counts. Stata has no way of knowing which terminology you, the user, regard as standard, natural, <span style="font-family: 'Courier New',Courier,monospace;"> obvious, intuitive, correct, familiar, charming, congenial or otherwise preferable.

<span style="font-family: 'Courier New',Courier,monospace;"> 2. On Statalist, rule 1 also applies. We don't necessarily know, and we are not obliged to care, that you are really or mostly a user or programmer of some other software or language and thus gravitate inevitably towards the terminology thereof.

<span style="font-family: 'Courier New',Courier,monospace;"> 3. What is true for Stata is not necessarily true for Mata.

__<span style="font-family: 'Courier New',Courier,monospace;"> Variable __ <span style="font-family: 'Courier New',Courier,monospace;"> A variable is a column or field in your dataset. It takes on a single value for each observation in your dataset. Stata's use of the term, although precise, should not be at odds with its general use within statistics.

<span style="font-family: 'Courier New',Courier,monospace;"> Confusion: Some people used to programming get accustomed to thinking of whatever holds a single value as a variable. Thus in lots of languages you can say something like

<span style="font-family: 'Courier New',Courier,monospace;"> x = 42

<span style="font-family: 'Courier New',Courier,monospace;"> and x is called a variable. Macros and scalars are typically used for that purpose in Stata. Neither macros nor scalars are correctly called variables in Stata.

__<span style="font-family: 'Courier New',Courier,monospace;"> Macros __ <span style="font-family: 'Courier New',Courier,monospace;"> A macro in Stata is a named object that holds a single string value. Macros thus have names and contents.

<span style="font-family: 'Courier New',Courier,monospace;"> The string can consist of numeric characters. Thus holding a string "42" is a way to hold the corresponding number 42. Users of such macros tend to think of them as containing numeric values. That usually is a convenient and helpful way to regard such macros, but in no sense is that intrinsic to their definition.

<span style="font-family: 'Courier New',Courier,monospace;"> Macros can be local or global. Local macros and global macros are often informally called locals or globals respectively.

<span style="font-family: 'Courier New',Courier,monospace;"> Confusion: In some other software the term macro is often used, either formally or informally, for a program or script that is written containing a sequence of commands. That is not standard usage in Stata. On occasion it could be that a Stata macro contains a program or do file name, but that is as may be.

__<span style="font-family: 'Courier New',Courier,monospace;"> Locals __ <span style="font-family: 'Courier New',Courier,monospace;"> Locals are, properly, local macros.

<span style="font-family: 'Courier New',Courier,monospace;"> Local refers both to the command -local- that defines a local macro and to the fact that such macros are only visible locally, meaning within the same program, do file, do-file editor contents or interactive session. Conversely a local macro is not visible within a different program, do file, do file editor contents or interactive session. Thus macros may be defined with the same name in different locations; such macros are completely different beasts.

<span style="font-family: 'Courier New',Courier,monospace;"> Confusion: Common references to locals, without the name macro, should not lead you to think that locals are a kind of variable. "Local variable" is a solecism in Stata.

__<span style="font-family: 'Courier New',Courier,monospace;"> Globals __ <span style="font-family: 'Courier New',Courier,monospace;">Globals are, properly, global macros.

<span style="font-family: 'Courier New',Courier,monospace;"> Global refers both to the command -global- that defines a global macro and to the fact that such macros are visible everywhere, or globally, meaning within any program, do file, or do-file editor contents and within an interactive session.

<span style="font-family: 'Courier New',Courier,monospace;"> Confusion: Common references to globals, without the name macro, should not lead you to think that globals are a kind of variable. "Global variable" is a solecism in Stata.