Announcement

Collapse
No announcement yet.
X
  • Filter
  • Time
  • Show
Clear All
new posts

  • SPSS Command to STATA

    Hello all;

    Anybody know how to transform the following SPSS command into a STATA command?
    Thank you

    USE ALL.
    COMPUTE filter_$=(B8_under5 = 1 | B8_under5 = 2 | B8_under5 = 3).
    VARIABLE LABELS filter_$ 'B8_under5 = 1 | B8_under5 = 2 | B8_under5 = 3 (FILTER)'.
    VALUE LABELS filter_$ 0 'Not Selected' 1 'Selected'.
    FORMATS filter_$ (f1.0).
    FILTER BY filter_$.
    EXECUTE.

  • #2
    I haven't used SPSS in the current millennium but I would guess that a translation to Stata (*) starts


    Code:
    gen wanted = inlist(B8_under5, 1, 2, 3) 
    label var wanted "B8_under5 1, 2 or 3" 
    label def wanted 0 "Not selected" 1 "Selected" 
    label val wanted wanted
    where you should choose your own variable name.

    (*) Not STATA. https://www.statalist.org/forums/help#spelling

    Comment


    • #3
      To Nick's correct code, I would add the note that the -filter by- command in SPSS does not fit with a typically Stata-ish way of doing things. To my recollection (?), SPSS's -filter by- command selects for analysis cases with the filter variable = 1, while excluding others. This restriction stays in effect until filtering is turned off. Analogous behavior can be produced in Stata with a preserve/restore sequence:
      Code:
      preserve
      keep if wanted == 1
      .... do whatever analysis is desired ...
      restore
      However, in most situations, things one might do by "filtering" in SPSS are accomplished in Stata with the if "qualifier" construction, without any preserve/restore construction, of which a prototype would be:
      Code:
      DoMyAnalysis if wanted == 1
      So, while the code can be literally translated as Nick shows, a more idiomatic translation might do good things for Paige.

      Comment

      Working...
      X